Connecting Tech Pros Worldwide Help | Site Map

Javascript Focus Command

 
LinkBack Thread Tools Search this Thread
  #1  
Old December 6th, 2005, 08:15 PM
amerar@iwc.net
Guest
 
Posts: n/a
Default 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 (emailvalidation(Email1,\"Illegal E-mail\")==false) {Email1.focus();
return false;};

Any suggestions?

Thanks.


  #2  
Old December 7th, 2005, 05:35 PM
Dr John Stockton
Guest
 
Posts: n/a
Default Re: Javascript Focus Command

JRS: In article <1133903068.176115.17850@g44g2000cwa.googlegroups. 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 (emailvalidation(Email1,\"Illegal E-mail\")==false) {Email1.focus();
>return false;};
>
>Any suggestions?[/color]

<URL:http://www.merlyn.demon.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.demon.co.uk/js-logic.htm#OO>, ditto.

<URL:http://www.merlyn.demon.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.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.