hypedup.co.uk
08-03-2002, 10:28 PM
i use the following script to make any spaces at the start or end of a form field to be deleted when the focus goes out of the form field. the only problem is if the person presses enter to submit the form, it doesnt remove the spaces for the field they are in. can anyone modify this script to fix this problem? thanks a lot, paul
heres the script:
function trimtext(txt) {
var temptext=txt.value.replace(/\s*/,'');
ets = temptext.substring(temptext.length-1, temptext.length);
while(ets==" ") {
temptext = temptext.substring(0, temptext.length-1);
ets = temptext.substring(temptext.length-1, temptext.length); }
txt.value = temptext; }
<input type="text" onchange="trimtext(this)">
heres the script:
function trimtext(txt) {
var temptext=txt.value.replace(/\s*/,'');
ets = temptext.substring(temptext.length-1, temptext.length);
while(ets==" ") {
temptext = temptext.substring(0, temptext.length-1);
ets = temptext.substring(temptext.length-1, temptext.length); }
txt.value = temptext; }
<input type="text" onchange="trimtext(this)">