Javascript Focus Command

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • amerar@iwc.net

    Javascript Focus Command

    Hi All,

    I have a form with multiple text boxes. I want to have one validation
    routine, and, if something fails, I'd like to put the focus in that
    text box.

    So, how can I 'remember' which text box I came from, so I know which to
    send the focus back to? They all have different names, but I do not
    want to code something like this for every text box:

    function datevalidation( entered, alertbox) {;
    with (entered) {;
    if (value==\"?\");
    {if (alertbox!=\"\" ) {alert(alertbox );} return false;};
    else {return true;};
    };
    };

    if (emailvalidatio n(Email1,\"Ille gal E-mail\")==false) {Email1.focus() ;
    return false;};

    Any suggestions?

    Thanks.

  • Dr John Stockton

    #2
    Re: Javascript Focus Command

    JRS: In article <1133903068.176 115.17850@g44g2 000cwa.googlegr oups.com>,
    dated Tue, 6 Dec 2005 13:04:28 local, seen in news:comp.lang. javascript,
    amerar@iwc.net posted :
    [color=blue]
    >I have a form with multiple text boxes. I want to have one validation
    >routine, and, if something fails, I'd like to put the focus in that
    >text box.
    >
    >So, how can I 'remember' which text box I came from, so I know which to
    >send the focus back to? They all have different names, but I do not
    >want to code something like this for every text box:
    >
    >function datevalidation( entered, alertbox) {;
    >with (entered) {;
    >if (value==\"?\");
    >{if (alertbox!=\"\" ) {alert(alertbox );} return false;};
    >else {return true;};
    >};
    >};
    >
    >if (emailvalidatio n(Email1,\"Ille gal E-mail\")==false) {Email1.focus() ;
    >return false;};
    >
    >Any suggestions?[/color]

    <URL:http://www.merlyn.demo n.co.uk/js-valid.htm#VFF>, but start reading
    at the beginning of the page.

    Also, ==false is silly; see ! in
    <URL:http://www.merlyn.demo n.co.uk/js-logic.htm#OO>, ditto.

    <URL:http://www.merlyn.demo n.co.uk/js-other.htm#Dbg> : Code should be
    indented, by a couple of spaces per level, to show the logical
    structure.

    There's no point is having an else after an if ... return.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
    <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

    Comment

    Working...