469,603 Members | 2,069 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,603 developers. It's quick & easy.

Why does my form keep submiting when I don't want it too?

Ajm113
161 100+
Ok for some reason after the update of Firefox it seems that my form keeps getting submitted when the user made a error on the form. I just want the page to reload so the user may try again. Because I have it so the submit button is a hit once only.

Here is the code:
Expand|Select|Wrap|Line Numbers
  1.     <SCRIPT LANGUAGE="JavaScript">
  2.  
  3. function validateForm(form)
  4. {
  5.  
  6.     if (form.username.value == "")
  7.     {
  8.     alert('You did not enter a username!');
  9.     form.username.focuse();
  10.     location.reload();
  11.     return false;
  12.     }else{
  13.  
  14.  
  15.     if (form.security_code.value != "DOOM34K10")
  16.     {
  17.     alert('You did not enter the correct security code!');
  18.     form.security_code.focuse();
  19.     location.reload();
  20.     return false;
  21.     }else{
  22.  
  23.     if (form.email.value == "") {
  24.     alert('We need to contact you through email!');
  25.     form.email.focus();
  26.     location.reload();
  27.     return false;
  28.     }else{
  29.  
  30.     if (form.email.value == "someone@site.com") {
  31.     alert('I am sure as heck that your email is not what you entered!');
  32.     form.email.focus();
  33.     location.reload();
  34.     return false;
  35.     }else{ 
  36.  
  37.     if (form.password1.value == "")
  38.     {
  39.     alert('You did not enter a password!');
  40.     form.password1.focuse();
  41.     location.reload();
  42.     return false;
  43.     }else{
  44.  
  45.     if (form.password2.value == "")
  46.     {
  47.     alert('You did not enter the second password!');
  48.     form.password2.focuse();
  49.     location.reload();
  50.     return false;
  51.     }else{
  52.  
  53.  
  54.     if (form.password1.value != form.password2.value)
  55.     {
  56.     alert('The passwords you entered are diffrent!');
  57.     form.password1.focuse();
  58.     form.password2.focuse();
  59.     location.reload();
  60.     return false;
  61.     }else{
  62.  
  63.  
  64. document.forms[0].submit();
  65. return true;
  66.         }
  67.             }
  68.         }
  69.     }
  70.         }
  71.     }
  72.             }
  73.         }
  74.  
  75.     </SCRIPT>
Aug 26 '07 #1
3 1215
acoder
16,027 Expert Mod 8TB
There's no point of the returns if you're going to navigate away from the page.

Your problem might be focuse() which should be focus().
Aug 27 '07 #2
Ajm113
161 100+
Thanks, it works fine now!
Aug 28 '07 #3
acoder
16,027 Expert Mod 8TB
Glad you got it working. Post again if you hit any more problems.
Aug 28 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Bruno Alexandre | last post: by
11 posts views Thread by Jozef | last post: by
14 posts views Thread by Anoop | last post: by
19 posts views Thread by Angus | last post: by
6 posts views Thread by bizt | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.