javascript keeps jumping back to focus

Please support our JavaScript / DHTML / AJAX advertiser: 50% Off 6 Months Web Hosting from 1&1. The World's #1 Host!
Thread Solved

Join Date: Oct 2009
Posts: 5
Reputation: fellathedog is an unknown quantity at this point 
Solved Threads: 0
fellathedog fellathedog is offline Offline
Newbie Poster

javascript keeps jumping back to focus

 
0
  #1
Nov 23rd, 2009
I have a validation function and the this is the last thing it does.

[code = var mytext=document.getElementById("sizip")
if(check5(mytext,"Zip Code must be 5 digits.")==false)
{mytext.focus();return false;}

function check5(mytext,alerttxt){
var re5digit=/^\d{5}$/ //regular expression defining a 5 digit number
if (mytext.value.search(re5digit)==-1) //if match failed
alert(alerttxt);return false; ]

It will validate ok, if I do not have 5 digits, I get an error box.

But then if I click the accept button again, it puts focus back on my zip code with no error.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 5
Reputation: fellathedog is an unknown quantity at this point 
Solved Threads: 0
fellathedog fellathedog is offline Offline
Newbie Poster

did you buy a book? fellathedog?

 
0
  #2
Nov 24th, 2009
Bad dog if you did not!

Fellathedog figured it out himself.

I needed to do an else in my function check5 and return true.

It was always returning false, hence, putting focus on, even when there was NOT an error condition.

GOOD DOG. FELLATHEDOG....

Hopefully, like a dog, the repetition will teach me...
Reply With Quote Quick reply to this message  
Reply

Tags
focus, javascript

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum


Views: 965 | Replies: 1
Thread Tools Search this Thread



Tag cloud for focus, javascript
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC