Page 185 - DCAP408_WEB_PROGRAMMING
P. 185
Unit 6: DOM Model
alert(alerttxt);return false; Notes
}
else
{
return true;
}
}
}
In the below example the entire script, with the HTML form could look something like this:
Example: Illustrating form validation.
<html>
<head>
<script type=”text/javascript”>
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value==””)
{
alert(alerttxt);return false;
}
else
{
return true;
}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_required(email,”Email must be filled out!”)==false)
{email.focus();return false;}
}
}
</script>
</head>
<body>
LOVELY PROFESSIONAL UNIVERSITY 179