
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.
Comment