Jump to content

Alert box form validation doesn't work in Firefox


ayok

Recommended Posts

Hi, I have a question regarding my form validation with javascript, which is working on IE, or even on Google chrome, but doesn't work on Firefox. The script is like below:

<script type="text/javascript">
<!--
  function validateClientForm()
  {
    if(document.clientInfo.name.value == ''){
      alert('your name please');
      clientInfo.name.focus();
      return false;
    }
    else if(document.clientInfo.adres.value == ''){
      alert('your address please');
      clientInfo.adres.focus();
      return false;
    }
}
// -->
</script>

<form name="clientInfo" method="post" action="send.php" onsubmit="return validateClientForm();">
<input type="text" name="name"/>
<input type="text" name="adres"/>

<input type="submit" value="send"/>
</form>

 

So in other browsers besides firefox, the warning appears if i don't fill in the name and address fields. And when i click ok, it stays on the same page. However in firefox, when i click ok after the alert box appears, it goes to the next page.

 

Could anyone tell me what's wrong with the codes or firefox?

 

Thanks,

ayok

try using === instead of ==:

 

 function validateClientForm()
  {
    if(document.clientInfo.name.value === ''){
      alert('your name please');
      clientInfo.name.focus();
      return false;
    }
    else if(document.clientInfo.adres.value === ''){
      alert('your address please');
      clientInfo.adres.focus();
      return false;
    }
}

Oh.. I tried the codes i wrote on my first post online, and it works. But the real script i have is much longer. I probably made mistake. I'm going to see first what's wrong. I'll get back if it still doesn't work.

 

Thank you for your replies. :)

 

ayok

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.