Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > bring focus to text field on submit

Reply
Thread Tools

bring focus to text field on submit

 
 
Dwayne Epps
Guest
Posts: n/a
 
      07-16-2003
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[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].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=="");
}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with focus on text field and submit button mahesh557 Software 0 05-23-2008 05:18 AM
Problem with focus on text field and submit button mahesh557 Software 0 05-23-2008 05:14 AM
this.window.focus() vs. window.focus() vs. this.focus() Roger Javascript 3 03-08-2007 08:53 PM
Why does putting focus on textbox also set focus to submit jw56578@gmail.com Javascript 2 06-06-2005 08:20 PM
HOWTO: Bring that row back into focus ... So ASP .Net Building Controls 2 05-13-2005 01:31 PM



Advertisments