PDA

View Full Version : Validate With Javascript?



sidorak95
12-29-2007, 07:18 PM
Am I doing something wrong with this page? When I click the Submit button, it's supposed to validate.

www.fungamesuniverse.com/form1.htm


<html>
<head>
<script type="text/javascript">
function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2)
{alert(alerttxt);return false;}
else {return true;}
}
}

function validate_form(thisform)
{
with (thisform)
{
if (validate_email(email,"Not a valid e-mail address!")==false)
{email.focus();return false;}
}
}
</script>
</head>

<body>
<form action="submitpage.htm"
onsubmit="return validate_form(this);"
method="post">
<p align="center">
<img border="0" src="Logo_Design.JPG" width="864" height="207">
<form action="submitpage.htm"
onsubmit="return validate_form(this);"
method="post">
<p align="center">Name:&nbsp;</p>
<p align="center"><input type="text" name="T1" size="20"></p>
<p align="center">
Email:
</p>
<p align="center">
<input type="text" name="email" size="20">
</p>
<p align="center">
Purpose Of Site:
</p>
<p align="center">
<input type="text" name="T2" size="20">
</p>
<p align="center">
Describe The Look:
</p>
<p align="center">
<textarea rows="2" name="S1" cols="20"></textarea>
</p>
</form>
<p align="center"><input type="submit" value="Submit">
</body>

</html>

linFox
12-29-2007, 09:01 PM
Just two little oversights:
One, you have two identical <form> opening tags, and two, your submit button is outside the form (just move it above the </form> tag and it'll work)

kgwd
12-30-2007, 04:29 PM
also needs to be a php file :D

sdasevne
12-30-2007, 07:35 PM
also needs to be a php file :D
It should work as an html file; I don't see any php code in it.