By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

Javascript Focus Command

P: n/a
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.

Dec 6 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
JRS: In article <11*********************@g44g2000cwa.googlegroups. com>,
dated Tue, 6 Dec 2005 13:04:28 local, seen in news:comp.lang.javascript,
am****@iwc.net posted :
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?


<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.
Dec 7 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.