Jan
23rd
Files under Javascript |
1,071 views
This tutorial will help you to remove spaces in a text field using Javascript. Any spaces keyed in by the user will be removed when they click on the button or anywhere outside the text field.

This string.split() is to find all the substrings in a string that are separated by one or more characters. Then, i used string.join() to join a sequence of strings.
My Sample of Codes:
You can try to copy and paste into a notepad and save it as .html to test and see the result.
<script language=”javascript” type=”text/javascript”>
function removeSpace(string) {
return string.split(’ ‘).join(”);
}
</script>
<form>
<input type=”text” onblur=”this.value=removeSpace(this.value);”>
<input type=”button” value=”Remove Space”>
</form>