How to Remove Spaces From a Text Field
This page shows you how to remove spaces from a text field. Any spaces entered by the user will be removed when they click anywhere outside the text field. Try it here:
Step 1
Add the following code to your head:
<script language="javascript" type="text/javascript">
function removeSpaces(string) {
var tstring = "";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++)
tstring += splitstring[i];
return tstring;
}
</script>
Step 2
Use the following code for your text field:
<form>
<input type="text" onblur="this.value=removeSpaces(this.value);">
<input type="button" value="Click">
</form>