I posted a question before about a form submitting to asp. I am more familiar with php so I decided to change the form to submit to php instead. The only thing is the form is created within an asp file contact.asp and I have submitted this to a contact.php page.
The problem is I am now trying to include validation into the head section of the asp page using JavaScript this is for an empty name, email and phone check. I have first tried just the name and email as:
The JavaScript I am using is as follows:
<script type="text/javascript">
function validateForm() {
var x=document.forms["myForm"]["fname"].value;
if (x==null || x=="") {
alert("First name must be filled out");
return false;
}
}
function validateForms() {
var x=document.forms["myForm"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) {
alert("Not a valid e-mail address");
return false;
}
}
</script>
I would highly appreciate any help with this.
Thanks
Edit: The JavaScript is not working it just submits the form without any validation
You’re declaring the same function twice. That won’t work. Rename one of the functions or merge them as one.
Also, make sure to actually call the function.
And make sure that the fields are called correctly.