954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

javascript keeps jumping back to focus

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.

fellathedog
Newbie Poster
5 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

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...

fellathedog
Newbie Poster
5 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: