View Full Version : Make a backspace
ekrub
07-19-2003, 08:34 AM
Is there a way that I can "write" a backspace to a form element? I have a javascript preventing users from typing illegal characters, but after it gives them the alert, the character is still there. Can I delete the character with Javascript?
Whitesword
07-19-2003, 08:59 AM
Yes you can... you just have to reevaluate the field in javascript, kill the illegal character and reset the value of the form field.
The best method is using replace function of the string object in Javascript. It uses regular exrpressions which I'm not all that terribly good at.
Something like (in pseudocode)
function checkform()
{
v = document.myform.myfield.value
illegalchar="" // This is the regular expression to look for
if( v.search(illegalchars) != -1) // look for illgal chars
{
v.replace( illegalcar, "" );
document.myform.myfield.value = v;
alert( "Illegal characters found in myfield");
document.myfield.myfield.focus();
return false;
}
// Everything's all right
return true;
}
Something like that anyway :)
HTH
Whitesword
vBulletin v3.0.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.