NOTE: I am a complete beginer i’ve been trying to learn javascript and am finding it very tough. What i want to ddo with the following code is just to get the email, postal code and the phone number fields validated, so if nothing is put in the field, or if the incorrect information isnt entered then a alert box will appear, now i’ve already got the email part working but i am totally clueless as how to write the next bit, i’ve put it as another script and i’m not sure if this is right, can someone tell me what i’m doing wrong here and guide me? like i said i am a completely new to this so go easy with me ?
[CODE]<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
“http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1″>
<title>A&B: Order a Pan (Sample Order Form)</title>
<link rel=”stylesheet” href=”styles/site.css” type=”text/css”>
<script language=”JavaScript” type=”text/javascript” src=”rollover.js”> </script>
<script language=”javascript” type=”text/javascript”>
re = /^w+([.-]?w+)*@w+([.-]?w+)(.w{2,3})+$/
function submitit(myform)
{
if(re.test(myform.emailaddr.value)){
return true
}
alert(“invalid email address”)
myform.emailaddr.focus()
myform.emailaddr.select()
return false
}
</script>
<script language=”javascript” type=”text/javascript”>
re = /^(?(d{3}))?[.-/]?(d{3})[.-/]?(d{4})$/
function submitit(myform){
validPhone = re.exec(myform.phone.value)
if(validPhone) {
myform.phone.value = “(” + validPhone[1] + “)” + validPhone[2] + “-” + validPhone[3]
}
else {
alert(myform.phone.value + ” isn’t a valid phone number”)
myform.phone.focus()
my.phone.select()
return false
}
//End hiding script –>
</script>
</head>
<body>
<!– Page-wide header –>
<div id=”header”>
<h1>Welcome to A & B<br>
Pots and Pans Ltd.</h1>
</div>
<!– Leftmost column contents –>
<div id=”left”>
<h2>Visit:</h2>
<ul class=”navlist”>
<li><a href=”index.htm” onMouseOver=”change_it(‘pic1’)” onMouseOut=”change_back(‘pic1’)”>
<img src=”home_hov.gif” name=”pic1″ id=”pic1″ border=”0″></a></li>
<li><a href=”main.htm” onMouseOver=”change_it(‘pic2’)” onMouseOut=”change_back(‘pic2’)”>
<img src=”intro_hov.gif” name=”pic2″ id=”pic2″ border=”0″></a></li>
<li><a href=”product1.htm” onMouseOver=”change_it(‘pic3’)” onMouseOut=”change_back(‘pic3’)”>
<img src=”pans_hov.gif” name=”pic3″ id=”pic3″ border=”0″></a></li>
<li><a href=”form.htm” onMouseOver=”change_it(‘pic4’)” onMouseOut=”change_back(‘pic4’)”>
<img src=”form_hov.gif” name=”pic4″ id=”pic4″ border=”0″></a></li>
<li><a href=”wishlist.htm” onMouseOver=”change_it(‘pic5’)” onMouseOut=”change_back(‘pic5’)”>
<img src=”wishlist_hov.gif” name=”pic5″ id=”pic5″ border=”0″></a></li>
<li><a href=”code.htm” onMouseOver=”change_it(‘pic6’)” onMouseOut=”change_back(‘pic6’)”>
<img src=”code_hov.gif” name=”pic6″ id=”pic6″ border=”0″></a></li>
</ul>
</div>
<!– Middle (main) column contents –>
<div id=”middle”>
<h2>Sample Order Information Form</h2>
<form onsubmit= “return submitit(this)” name=”myform” action=”somesite.cfm”>
<table cellpadding=”5″>
<tr>
<td><h3>Shipping Information</h3></td>
<td> </td>
</tr>
<tr>
<td><label for=”shipFirstName”>First Name</label></td>
<td><input type=”text” name=”shipFirstName” id=”shipFirstName” maxlength=”30″></td>
</tr>
<tr>
<td><label for=”shipFamilyName”>Family Name</label></td>
<td><input type=”text” name=”shipFamilyName” id=”shipFamilyName” maxlength=”30″></td>
</tr>
<tr>
<td><label for=”phone”>Contact Telephone Number</label></td>
<td><input type=”text” name=”phone” id=”phone” maxlength=”30″></td>
</tr>
<tr>
<td><label for=”shipHouseNumber”>House Number</label></td>
<td><input type=”text” name=”shipHouseNumber” id=”shipHouseNumber” maxlength=”30″></td>
</tr>
<tr>
<td><label for=”shipStreetName”>Street Name</label></td>
<td><input type=”text” name=”shipStreetName” maxlength=”30″></td>
</tr>
<tr>
<td><label for=”shipCity”>City</label></td>
<td><input type=”text” name=”shipCity” id=”shipCity” maxlength=”30″></td>
</tr>
<tr>
<td><label for=”shipPostalCode”>Postal Code</label></td>
<td><input type=”text” name=”shipPostalCode” id=”shipPostalCode” maxlength=”30″></td>
</tr>
<tr>
<td><h3>Billing Information</h3></td>
<td> </td>
</tr>
<tr>
<td><label for=”billFirstName”>First Name</label></td>
<td><input type=”text” name=”billFirstName” id=”billFirstName” maxlength=”30″></td>
</tr>
<tr>
<td><label for=”billFamilyName”>Family Name</label></td>
<td><input type=”text” name=”billFamilyName” id=”billFamilyName” maxlength=”30″></td>
</tr>
<tr>
<td><label for=”emailaddr”>Email Address</label></td>
<td><input type=”text” name=”emailaddr” id=”emailaddr” maxlength=”30″></td>
</tr>
<tr>
<td><label for=”phone”>Contact Telephone Number</label></td>
<td><input type=”text” name=”phone” id=”phone” maxlength=”30″></td>
</tr>
<tr>
<td><label for=”billCardNumber”>Credit Card Number</label></td>
<td><input type=”text” name=”billCardNumber” id=”billCardNumber” maxlength=”30″></td>
</tr>
<tr>
<td><label for=”billCardType”>Credit Card Type</label></td>
<td><input type=”text” name=”billCardType” id=”billCardType” maxlength=”30″>Visa/MasterCard</td>
</tr>
<tr>
<td><label for=”instructions”>Special Instructions</label></td>
<td>
<textarea name=”instructions” id=”instructions” rows=”8″ cols=”30″>Enter your requirements here or comments.</textarea></td>
</tr>
<tr>
<td><input type=”submit” name=”Submit” id=”Submit” value=”Submit”></td>
<td> </td>
</tr>
</table>
</form>
</div>
<!– Rightmost column contents –>
<div id=”right”>
<h2>Your cart:</h2>
<div class=”cartitems” id=”itemlist”>
<p>No items</p>
</div>
</div>
<!– Page-wide footer –>
<div id=”footer”>
<p>©2007 A&B Ltd.</p>
</div>
</body>
</html>