good day!
I have a php form. I have made some ajax validation on it but everytime i click the submit button it does not validate, and when I try to issue an alert command on ajax function, it returns undefined on certain variables?
Here is my present code:
<Form codes>
<form method="POST" id="newsletter-form" name="newsletter-form" onSubmit="return doSubmit();">
<p>
<label for="name">Your name</label>
<input type="text" name="name" id="name" value="" tabindex="1" />
</p>
<p>
<label for="email">Your email address</label>
<input type="text" name="email" id="email" value="" tabindex="2" />
</p>
<p>
We hate spammers!<br />
<input type="submit" value="Join Us" />
</p>
</form>
<Ajax validation codes>
function doSubmit(){
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var name = $('newsletter-form [name="name"]').val();
var email_address = $('newsletter-form [name="email"]').val();
if(name == ""){
alert("Please enter your name.");
return false;
}
if(email_address == ""){
alert("Your email is required.");
return false;
}
};
Thanks for helping..!