<!-- JavaScript:Forms code snippet 6. -->
<!-- Simple form which intercepts a form's 'submit' button -->
<!-- Simple form validation to test if user has entered
any value into the form element. -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- Code source: http://www.justfigures.co.uk/ -->
<!-- A resource for web developers using XHTML, CSS, JavaScript, PHP -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View code snippet page</title>
<script language="JavaScript" type="text/javascript">
/* function to test if user has entered any value
into the form element */
function emailAddress(form)
{
// note use of 'not equal to' '!='
if (form.text1.value != "")
{
return true
}
else
{
window.alert('Please enter your email address.')
form.text1.focus()
return false
}
}
</script>
</head>
<body>
<!-- note that 'this' is equivalent to 'document.feedbackForm' -->
<!-- note the use of the keyword 'return' here when calling the function -->
<form name="feedbackForm" id="feedbackForm" onsubmit="return emailAddress(this)" action="6_testLink2.php">
Please enter your email address:<br />
<input type="text" name="text1" value="" /><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>