I need to create a script that will validate all of the text boxes the user must fill out by ensuring that:
1. the user inputs doesn’t leave any boxes empty
2. the user inputs a valid zip code
3. the user inputs a valid a email address
<!-- Hide script from older browsers
function isNum(passedVal) {
if (passedVal == "") {
return false
}
for (i=0; i<passedVal.length; i++) {
if (passedVal.charAt(i) < "0") {
return false
}
if (passedVal.charAt(i) > "9") {
return false
}
}
return true
}
function validZip(inZip) {
if (inZip == "") {
return true
}
if (isNum(inZip)) {
return true
}
return false
}
function submitIt(carForm) {
if (carForm.zip.value == "" && carForm.dealerList.selectedIndex == -1) {
alert("You must either enter a Zip code, or pick the dealer closest to you")
carForm.zip.focus()
return false
}
if (!validZip(carForm.zip.value)) {
alert("That is an invalid Zip code")
carForm.zip.focus()
carForm.zip.select()
return false
}
return true
}
// End hiding script -->
</SCRIPT>
<!-- Hide script from older browsers
function validEmail(email) {
invalidChars = " /:,;"
if (email == "") {
return false
}
for (i=0; i<invalidChars.length; i++) {
badChar = invalidChars.charAt(i)
if (email.indexOf(badChar,0) > -1) {
return false
}
}
atPos = email.indexOf("@",1)
if (atPos == -1) {
return false
}
if (email.indexOf("@",atPos+1) > -1) {
return false
}
periodPos = email.indexOf(".",atPos)
if (periodPos == -1) {
return false
}
if (periodPos+3 > email.length) {
return false
}
return true
}
function submitIt(carForm) {
if (!validEmail(carForm.emailAddr.value)) {
alert("Invalid email address")
carForm.emailAddr.focus()
carForm.emailAddr.select()
return false
}
return true
}
// End hiding script -->
</SCRIPT>
Using the two code examples above how to I change it to fit into this page? -->
<html>
<head>
<title>Ask us about Skiing in Montana</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="4" height="10" valign="top"></td>
<td width="61" height="10" valign="top"></td>
<td width="37" height="10" valign="top"></td>
<td width="25" height="10" valign="top"></td>
<td width="12" height="10" valign="top"></td>
<td width="490" height="10" valign="top"></td>
<td width="9" height="10" valign="top"></td>
<td width="68" height="10" valign="top"></td>
</tr>
<tr>
<td width="4" height="30" valign="top"></td>
<td width="61" height="30" valign="top"></td>
<td width="37" height="30" valign="top"></td>
<td width="25" height="30" valign="top"></td>
<td width="12" height="30" valign="top"></td>
<td width="490" height="112" rowspan="2" valign="top">
<h1 align="center">Let us Tell you More about<br>
Skiing in Montana</h1>
</td>
<td width="9" height="30" valign="top"></td>
<td width="68" height="30" valign="top"></td>
</tr>
<tr>
<td width="4" height="82" valign="top"></td>
<td width="98" height="82" colspan="2" valign="top"><img src="backup.gif"></td>
<td width="25" height="82" valign="top"></td>
<td width="12" height="82" valign="top"></td>
<td width="9" height="82" valign="top"></td>
<td width="68" height="82" valign="top"></td>
</tr>
<tr>
<td width="4" height="182" valign="top"></td>
<td width="61" height="182" valign="top"></td>
<td width="37" height="182" valign="top"></td>
<td width="25" height="182" valign="top"></td>
<td width="511" height="182" colspan="3" valign="top">
<p><b>We'd love to tell you all about our great state and why thousands of skiers
keep coming back year.</b></p>
<p><b> Call us at 1-800-Ski-MNTA<br>
and we will answer any questions you have.</b></p>
<p><b>You can also just fill out the form below and we will mail you a kit to
aid you in planning your next ski adventure.</b></p>
</td>
<td width="68" height="182" valign="top"></td>
</tr>
<tr>
<td width="4" height="146" valign="top"></td>
<td width="61" height="146" valign="top"></td>
<td width="641" height="146" colspan="6" valign="top">
<form method="post" action="">
<p><b>Full Name: </b>
<input type="text" name="textfield" size="30">
</p>
<p>
<b>Street Address: </b>
<input type="text" name="textfield2" size="50">
</p>
<p><b>City:</b>
<input type="text" name="textfield3">
<b>State:</b>
<input type="text" name="textfield4" size="3">
<b>Zip Code: </b>
<input type="text" name="textfield5" size="10">
</p>
<p>
<b> Email: </b>
<input type="text" name="textfield6" size="40">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
<input type="submit" name="Submit2" value="Reset">
</p>
</form>
</td>
</tr>
<tr>
<td width="4" height="1" valign="top"><img width="4" height="1" src="transparent.gif"></td>
<td width="61" height="1" valign="top"><img width="61" height="1" src="transparent.gif"></td>
<td width="37" height="1" valign="top"><img width="37" height="1" src="transparent.gif"></td>
<td width="25" height="1" valign="top"><img width="25" height="1" src="transparent.gif"></td>
<td width="12" height="1" valign="top"><img width="12" height="1" src="transparent.gif"></td>
<td width="490" height="1" valign="top"><img width="490" height="1" src="transparent.gif"></td>
<td width="9" height="1" valign="top"><img width="9" height="1" src="transparent.gif"></td>
<td width="68" height="1" valign="top"><img width="68" height="1" src="transparent.gif"></td>
</tr>
</table>
</body>
</html>
And how to I make sure that users do not leave any text boxes empty?