PDA

View Full Version : My form validates correctly, but submits regardless


bubba_nuts
07-13-2002, 06:56 AM
:mad:
I built a form for a pet project of mine, and wrote a little JavaScript to validate it and make sure all fields are completed. If they aren't a box pops up and says so. The problem is that the box pops up and the form still submits.


HEAD:

<script language="JavaScript">
function validate()
{
if (document.request.name.value == '')
{
alert("All fields must be completed!");
return false;
}
if (document.request.location.value == '')
{
alert("All fields must be completed!");
return false;
}
if (document.request.computer.value == '')
{
alert("All fields must be completed!");
return false;
}
return true;
}
</script>


BODY:

<form name="request" onSubmit="validate();" action="Action.lasso" method=POST>
<input type="text" name="name" size="30" value="" maxlength="30">
<input type="text" name="location" size="30" maxlength="30">
<input type="text" name="computer" size="30" maxlength="30">
<input type="submit" value="Submit">
</form>


(I've cut out all but what's important.) The form actuall has several other fields, but I can't even get these to work.

jkd
07-13-2002, 07:01 AM
<form name="request" onSubmit="return validate();" action="Action.lasso" method="POST">

:D

bubba_nuts
07-13-2002, 07:06 AM
:mad: Grrrrr....

I knew it was something ridiculously simple.


Thank you!!