Forum Moderators: open

Message Too Old, No Replies

problem with "return false"

         

Acternaweb

5:53 pm on Apr 7, 2005 (gmt 0)

10+ Year Member



I am having a problem with return false working. It works fine in all my fields but this one. If the user doesn't enter 5 numbers, I want them brought back to the field. Do not goto the next field. What do I have wrong here?

{
var re5digit=/^\d{5}$/
if (document.feedbackform.zip.value.search(re5digit)==-1)
alert("Please enter a valid 5 digit zip code");
document.feedbackform.zip.focus();
return false;

}

}

if (document.feedbackform.country.value == 'select_your_country') {
alert("Please provide us with a selection.\n");
document.feedbackform.country.focus()
return false;
}

encyclo

6:06 pm on Apr 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A missing semi-colon, perhaps?:

if (document.feedbackform.country.value == 'select_your_country') {
alert("Please provide us with a selection.\n");
document.feedbackform.country.focus()
;
return false;
}

Acternaweb

7:33 pm on Apr 7, 2005 (gmt 0)

10+ Year Member



encyclo

that didn't work. it seems it has to do something with this one;

{
var re5digit=/^\d{5}$/
if (document.feedbackform.zip.value.search(re5digit)==-1)
alert("Please enter a valid 5 digit zip code");
document.feedbackform.zip.focus();
return false;

}

if I take the "return false" it works, but if the entry is "true" i can't get to the next field

kaled

9:12 pm on Apr 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Without seeing the whole thing, this is just a guess. You may need an else part to your if statement.

{
var re5digit=/^\d{5}$/
if (document.feedbackform.zip.value.search(re5digit)==-1) {
alert("Please enter a valid 5 digit zip code");
document.feedbackform.zip.focus();
return false
}
else return true
}

Kaled.

lafTrak

2:31 am on Apr 30, 2005 (gmt 0)



Syntax error.

Opening bracket needs to come after:
if (document.feedbackform.zip.value.search(re5digit)==-1)