Jump to content

Form Entry Validation


ainoy31

Recommended Posts

Hello-

 

I can not figure why my javascript is not validation my entry on a form I created.  Here is the javascript code:

 

<script type = "text/javascript" language="javascript">

<!--

 

function Validate()

{

if(document.quickquote.p_address.value.length == 0)

{

alert("Please enter a valid street address,  e.g. 7500 Canyon Drive");

return false;

}

if(document.quickquote.p_city.value.length == 0)

{

alert("Please enter city, e.g. Dallas");

return false;

}

if(document.quickquote.p_state.value.length == 0) || (document.quickquote.p_state.value.length < 2) || (!isLetter(document.quickquote.p_state.charAt(o))) || (!isLetter(document.quickquote.p_state.value.charAt(1))))

{

alert("Please enter 2 character state abbreviation");

return false;

}

if(document.quickquote.p_zip.value.length != 5) && (document.quickquote.p_zip.value != 9)

{

alert("Invalid zipcode format, 66204");

return false;

}

 

if(document.quickquote.d_address.value.length == 0)

{

alert("Please enter street address, e.g. 7500 Canyon Drive");

return false;

}

if(document.quickquote.d_city.value.length  == 0)

{

alert("Please enter city, e.g. Dallas");

return false;

}

if(document.quickquote.d_state.value.length == 0) || (document.quickquote.d_state.value.length < 2) || (!isLetter(document.quickquote.d_state.charAt(o))) || (!isLetter(document.quickquote.d_state.value.charAt(1))))

{

alert("Please enter 2 character state abbreviation");

return false;

}

if(document.quickquote.d_zip.value.length != 5) && (document.quickquote.d_zip.value != 9)

{

alert("Invalid zipcode format, e.g. 66204");

return false;

}

return true;

}

 

function isLetter©

{

return (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")))

}

 

function isDigit©

{

return ((c >= "0") && (c <= "9"))

}

// -->

</script>

 

The form code is:

 

<form name="quickquote" action="process1.php" method= "post" onSubmit="return Validate();">

<div class = "content">

<h2>Enter your information to receive your QuickQuote!</h2><br>

<p>Pickup Location</p>

<br>

Address: <input type="text" name="p_address" size="30" /><br>

City:       <input type="text" name="p_city" size="30" /><br>

State:     <input type="text" name="p_state" size="5" /><br>

Zip:         <input type="text" name="p_zip" size="5" /><br>

 

<br>

<br>

<p>Destination Location</p>

<br>

Address: <input type = "text" name = "d_address" size = "30" /><br>

City:       <input type = "text" name = "d_city" size = "30" /><br>

State:     <input type="text" name="d_state" size="5" /><br>

Zip:         <input type="text" name="d_zip" size="5" /><br>

<br>

<center><input type = "Submit" name = "Submit" value = "Submit" /></center>

</div>

</form>

 

If I leave the address field empty, the form still gets processed.  Much appreciation.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.