D
Dwayne Epps
I'm using a RegExp Validator extension on a text field and was curious if
anyone know how to edit the following code to bring focus and select the
string within the text field when invalid characters are entered, so the
user can correct the invalid entry? Currently, the extension will validate
the first text field and continue on to the next text field after the user
clicks on the error message. If possible, I would like the text field to be
brought back to focus and select the invalid string within the text field
after the user clicks on the error message before it begins validating the
next text field. Any ideas? Thanks in advance.
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers.document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function tmt_regExpValidator(f,re,eMsg,ru,r){
var myErr="";var fv=MM_findObj(f).value;var rex=new RegExp(unescape(re));
var
t=eval(ru+rex.test(fv));if(r){if(fv.length<=0||!t){alert(unescape(eMsg));myE
rr+="eMsg";}}
else
if(fv.length>0&&!t){alert(unescape(eMsg));myErr+="eMsg";}document.MM_returnV
alue=(myErr=="");
}
anyone know how to edit the following code to bring focus and select the
string within the text field when invalid characters are entered, so the
user can correct the invalid entry? Currently, the extension will validate
the first text field and continue on to the next text field after the user
clicks on the error message. If possible, I would like the text field to be
brought back to focus and select the invalid string within the text field
after the user clicks on the error message before it begins validating the
next text field. Any ideas? Thanks in advance.
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers.document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function tmt_regExpValidator(f,re,eMsg,ru,r){
var myErr="";var fv=MM_findObj(f).value;var rex=new RegExp(unescape(re));
var
t=eval(ru+rex.test(fv));if(r){if(fv.length<=0||!t){alert(unescape(eMsg));myE
rr+="eMsg";}}
else
if(fv.length>0&&!t){alert(unescape(eMsg));myErr+="eMsg";}document.MM_returnV
alue=(myErr=="");
}