<html>
<head>
<title>Form Javascript</title>
<link rel="StyleSheet" type="text/css" href="headline.css">
<script type="text/javascript">
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
function checkmail(fieldID){
email = document.getElementById(fieldID);
var returnval=emailfilter.test(email.value)
if (returnval==false){
alert("Please enter a valid email address.")
email.select()
}
return returnval
}
function checkName(fieldID) {
nameField = document.getElementById(fieldID);
//Trim the value
nameField.value = nameField.value.replace(/^\s+|\s+$/g, '');
if (!nameField.value) {
alert("Please enter a valid name.")
nameField.select()
return false;
}
return true;
}
function checkForm() {
if (!checkName('myName')) { return false; }
if (!checkName('surname')) { return false; }
if (!checkmail('myemail')) { return false; }
var htmlOutput = "<H1>Your results</H1>";
htmlOutput += "
First Name: " + document.getElementById('myName').value;
htmlOutput += "
Last Name: " + document.getElementById('surname').value;
htmlOutput += "
Age Range: " + document.getElementById('Age').value;
htmlOutput += "
Email Address: " + document.getElementById('myemail').value;
document.getElementById('theBody').innerHTML = htmlOutput;
}
</script>
</head>
<body id="theBody">
<H1>Simple Form</H1>
<form onsubmit="checkForm(this);return false;">
First Name: <input type="text" name="myName" id="myName" size="40" maxlength="256"></P>
Second Name: <input type="text" name="surname" id="surname" size="40" maxlength="256"></P>
Age range :
<select name="Age" id="Age">
<option value="16-21">16-21</option>
<option value="21-25">21-25</option>
<option value="25+">25+</option>
</select></P>
Email Address: <input type="text" name="myemail" id="myemail" style="width: 270px">
<input type="submit" value="Submit" />
<input type="reset" value="Reset"></P>
</form>
</body>
</html>
Michael J