bring focus to text field on submit

Discussion in 'Javascript' started by Dwayne Epps, Jul 16, 2003.

  1. Dwayne Epps

    Dwayne Epps Guest

    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=="");
    }
     
    Dwayne Epps, Jul 16, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. So

    HOWTO: Bring that row back into focus ...

    So, May 3, 2005, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    138
  2. So

    HOWTO: Bring that row back into focus ...

    So, May 3, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    118
  3. Replies:
    0
    Views:
    113
  4. So

    HOWTO: Bring that row back into focus ...

    So, May 3, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    132
  5. Dai Ba Wong
    Replies:
    3
    Views:
    165
    kaeli
    Jul 6, 2004
Loading...

Share This Page