Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Ajm113's Avatar
Familiar Sight
 
Join Date: Jun 2007
Posts: 161
#1: Aug 27 '07
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>

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Aug 27 '07

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


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().
Ajm113's Avatar
Familiar Sight
 
Join Date: Jun 2007
Posts: 161
#3: Aug 28 '07

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


Thanks, it works fine now!
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Aug 28 '07

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


Glad you got it working. Post again if you hit any more problems.
Reply