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

Link to comment
Share on other sites

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;
    }
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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