bring focus to text field on submit

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=="");
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top