JavaScript Tutorials
Validate Form Fields
validate_form.html
<html>
<head>
<script type="text/javascript">
function validateDemoForm() {
if (document.demoForm.firstName.value == "")
{
alert('Please fill out your first name');
return false;
}
else if (document.demoForm.lastName.value == "")
{
alert('Please fill out your last name');
return false;
}
return true;
}
</script>
<title>Validate Form</title>
</head>
<body>
<form name="demoForm" method="post" action="" onSubmit="return validateDemoForm();">
First Name: <input name="firstName" type="text">
Last Name: <input name="lastName" type="text">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
Validate Form
JavaScript Tutorials
Other Tutorials
© Morina Internet Solutions - All Rights Reserved