Sorry to reply to my own reply but this gives a better picture of where I am now. I have functions that will check the required fields but am not sure how to get them to work together. In teh attached code I've tried to use buttons toc heck the post code and the email fields independently (p code works and email doesnet) NB this email function works fien when I take it off this page.
If you coudl advise me how to either:
a/ get the email button to activate the email function correctly
or
b/ how to link my 3 functions together that would be great.
Really lost here!!!
<head>
<script type="text/javascript">
<!--
function validate_form ( )
{
valid = true;
if ( document.contact_form.shipFirstName.value == "" )
{
alert ( "Please fill in the 'Your First Name' box." );
valid = false;
}
if ( document.contact_form.shipFamilyName.value == "" )
{
alert ( "Please fill in the 'Your Family Name' box." );
valid = false;
}
if ( document.contact_form.pcode.value == "" )
{
alert ( "Please fill in the 'Post Code' box." );
valid = false;
}
return valid;
}
//-->
</script>
<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!!
http://javascript.internet.com -->
<!-- Original code by Peter Haydon -->
<!--
peter_haydon@lineone.net -->
<!-- Begin
function postit(){ //check postcode format is valid
test = document.contact_form.pcode.value; size = test.length
test = test.toUpperCase(); //Change to uppercase
while (test.slice(0,1) == " ") //Strip leading spaces
{test = test.substr(1,size-1);size = test.length
}
while(test.slice(size-1,size)== " ") //Strip trailing spaces
{test = test.substr(0,size-1);size = test.length
}
document.contact_form.pcode.value = test; //write back to form field
if (size < 6 || size > 8){ //Code length rule
alert(test + " is not a valid postcode - wrong length");
document.contact_form.pcode.focus();
return false;
}
if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
alert(test + " is not a valid postcode - cannot start with a number");
document.contact_form.pcode.focus();
return false;
}
if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule
alert(test + " is not a valid postcode - alpha character in wrong position");
document.contact_form.pcode.focus();
return false;
}
if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
alert(test + " is not a valid postcode - number in wrong position");
document.contact_form.pcode.focus();
return false;
}
if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
alert(test + " is not a valid postcode - number in wrong position");
document.contact_form.pcode.focus();
return false;
}
if (!(test.charAt(size-4) == " ")){//space in position length-3 rule
alert(test + " is not a valid postcode - no space or space in wrong position");
document.contact_form.pcode.focus();
return false;
}
count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
if (count1 != count2){//only one space rule
alert(test + " is not a valid postcode - only one space allowed");
document.contact_form.pcode.focus();
return false;
}
alert("Postcode Format OK");
return true;
}
// End -->
</script>
<script type="text/javascript">
function validate_email(field,alerttxt)
{
with (document.contact_form.)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2)
{alert(alerttxt);return false;}
else {return true;}
}
}function validate_contact(contact_form)
{
with (document.contact_form.billEmailAddress)
{
if (validate_email(email,"Not a valid e-mail address!")==false)
{email.focus();return false;}
}
alert ( "Email is valid pls press submit." );
}
</script>
</head>
<body>
<!-- Page-wide header -->
<div id="header">
</div>
<!-- Leftmost column contents -->
<div id="left">
<h2>Visit:</h2>
<ul class="navlist">
<li><a href="index.html">Home</a></li>
<li><a href="product.html">Our pans</a></li>
<li><a href="contact.html">Contact us</a></li>
<li><a href="form.html">Order</a></li>
</ul>
</div>
<!-- Main column contents -->
<div id="middle"> <!-- InstanceBeginEditable name="body" --><h2>Sample Order Information Form</h2>
<form name="contact_form" method="post" action="#" onSubmit="return validate_form ( );">
<table cellpadding="5">
<tr>
<td><h3>Shipping Information</h3></td>
<td> </td>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" name="shipFirstName" maxlength="30" /></td>
</tr>
<tr>
<td>Surname</td>
<td><input type="text" name="shipFamilyName" maxlength="30" /></td>
</tr>
<tr>
<td>Contact Telephone Number</td>
<td><input type="text" name="shipPhoneNumber" maxlength="30" /></td>
</tr>
<tr>
<td>Street Name</td>
<td><input type="text" name="shipStreetName" maxlength="30" /></td>
</tr>
<tr>
<td>City</td>
<td><input type="text" name="shipCity" maxlength="30" /></td>
</tr>
<tr>
<td>Postal Code</td>
<td><input type="text" name="pcode" maxlength="30" /></td>
<td><input type="button" name="Button" value="Check Code" onclick="postit()"></td>
</tr>
<tr>
<td><h3>Billing Information</h3></td>
<td> </td>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" name="billFirstName" maxlength="30" /></td>
</tr>
<tr>
<td>Surname</td>
<td><input type="text" name="billFamilyName" maxlength="30" /></td>
</tr>
<tr>
<td>Email address</td>
<td><input type="text" name="billEmailAddress" maxlength="30" /></td>
<td> <input type="button" name="Button" value="Check Code" onclick="return validate_contact(contact_form);"> </td>
</tr>
<tr>
<td>Contact Telephone Number</td>
<td><input type="text" name="billPhoneNumber" maxlength="30" /></td>
</tr>
<tr>
<td>Credit Card Number</td>
<td><input type="text" name="billCardNumber" maxlength="30" /></td>
</tr>
<tr>
<td>Credit Card Type</td>
<td><select name="billCardType">
<option value="...">Choose your card...</option>
<option value="visa">Visa</option>
<option value="mastercard">Mastercard</option>
</select> </td>
</tr>
<tr>
<td>Instructions</td>
<td>
<textarea name="instructions" rows="8" cols="30">Enter your requirements here or comments.</textarea></td>
</tr>
<tr>
<td><input type="submit" name="Send" value="Submit" /></td>
<td> </td>
</tr>
</table>
</form><!-- InstanceEndEditable --></div>
<!-- Page-wide footer -->
<div id="footer">
</div>
</body>
<!-- TemplateEnd -->
<!-- InstanceEnd --></html>