SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Validation...

  1. #1
    SitePoint Zealot sethtrain's Avatar
    Join Date
    Dec 2003
    Location
    Paducah, KY
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Validation...

    I am in need of some validation tips. I have to be able to check to see if some checkboxes are checked (such as SAME AS BILLING ADDRESS) and if they are then copy the information (from shipping address) to the billing address area. I am also in need of a way to enable credit card information if a check box in checked.

    Thanks in advance...
    --
    sethtrain

  2. #2
    SitePoint Addict Guimauve's Avatar
    Join Date
    Aug 2004
    Location
    Chicago
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can add an onclick event to your "Same as billing address" checkbox and when the value of the checkbox is checked you copy the values from the billing address to the shipping address then disable the form fields. Example:

    Code:
    <html>
    <head>
      <title>Test of Shipping and Billing Address</title>
      <script>
        function CopyBillingAddress() {
    
          with (document.form1) {
    
            if (sameAsBillTo.checked) {
              shipToAddress1.value = billToAddress1.value ;
              shipToAddress2.value = billToAddress2.value ;
              shipToAddress3.value = billToAddress3.value ;
              shipToCity.value = billToCity.value ;
              shipToState.value = billToState.value ;
              shipToZip.value = billToZip.value ;
    
              shipToAddress1.disabled = true ;
              shipToAddress2.disabled = true ;
              shipToAddress3.disabled = true ;
              shipToCity.disabled = true ;
              shipToState.disabled = true ;
              shipToZip.disabled = true;
              }
            else {
              shipToAddress1.disabled = false ;
              shipToAddress2.disabled = false ;
              shipToAddress3.disabled = false ;
              shipToCity.disabled = false ;
              shipToState.disabled = false ;
              shipToZip.disabled = false;
              }
            }
          }
      </script>
      <style>
        label {
          text-align: right;
          width: 200px;
          position: relative;
          font-weight: bold;
          padding-right: 10px;
          }
        </style>
    </head>
    <body>
    <form name="form1">
    <label>Bill To Address</label>
    <input type="text" name="billToAddress1" onchange="CopyBillingAddress()"><br>
    <label>&nbsp;</label>
    <input type="text" name="billToAddress2" onchange="CopyBillingAddress()"><br>
    <label>&nbsp;</label>
    <input type="text" name="billToAddress3" onchange="CopyBillingAddress()"><br>
    <label>City</label>
    <input type="text" name="billToCity" onchange="CopyBillingAddress()"><br>
    <label>State</label>
    <input type="text" name="billToState" onchange="CopyBillingAddress()"><br>
    <label>Zip</label>
    <input type="text" name="billToZip" onchange="CopyBillingAddress()"><br>
    <p>
    <input type="checkbox" name="sameAsBillTo" value="1" onclick="CopyBillingAddress(this)">Same as Bill To<br>
    <label>Ship To Address</label>
    <input type="text" name="shipToAddress1"><br>
    <label>&nbsp;</label>
    <input type="text" name="shipToAddress2"><br>
    <label>&nbsp;</label>
    <input type="text" name="shipToAddress3"><br>
    <label>City</label>
    <input type="text" name="shipToCity"><br>
    <label>State</label>
    <input type="text" name="shipToState"><br>
    <label>Zip</label>
    <input type="text" name="shipToZip"><br>
    </form>
    </body>
    </html>
    Charles

  3. #3
    SitePoint Zealot sethtrain's Avatar
    Join Date
    Dec 2003
    Location
    Paducah, KY
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have been trying different things but i can't get it. Here is the HTML:

    HTML Code:
    <fieldset>
    		<legend>Shipping Address</legend>
    		<table width="100%"  border="0">
    		  <tr>
    			<td>Name:</td>
    			<td><input name="name" type="text" size="50"></td>
    		  </tr>
    		  <tr>
    			<td valign="top">Street:</td>
    			<td><textarea name="address" cols="65" rows="5"></textarea></td>
    		  </tr>
    		  <tr>
    			<td>City:</td>
    			<td>
    			<input name="city" type="text" size="35"> <label for="state">State:</label> <select name="state">
    			  <option selected>State</option>
    			  <option>AL</option>
    			  <option>AK</option>
    			  <option>AZ</option>
    			  <option>AR</option>
    			  <option>CA</option>
    			  <option>CO</option>
    			  <option>CT</option>
    			  <option>DE</option>
    			  <option>DC</option>
    			  <option>FL</option>
    			  <option>GA</option>
    			  <option>HI</option>
    			  <option>ID</option>
    			  <option>IL</option>
    			  <option>IN</option>
    			  <option>IA</option>
    			  <option>KS</option>
    			  <option>KY</option>
    			  <option>LA</option>
    			  <option>ME</option>
    			  <option>MD</option>
    			  <option>MI</option>
    			  <option>MN</option>
    			  <option>MS</option>
    			  <option>MO</option>
    			  <option>MT</option>
    			  <option>NE</option>
    			  <option>NV</option>
    			  <option>NH</option>
    			</select> <label for="zip">Zip</label> <input name="zip" type="text" size="10">
    			</td>
    		  </tr>
    		</table>
    		</fieldset>
    		</td>
          </tr>
          <tr>
            <td colspan="2">
    		<fieldset>
    		<legend>Billing Address</legend>
    		<table width="100%"  border="0">
    		  <tr>
    			<td colspan="2"><input name="same" type="checkbox" onClick="sameischecked();" value=""><label for="same">Same as Billing Address</label> <input name="billme" type="checkbox"><label for="billme">Bill me now with my credit card.</label></td>
    			</tr>
    		   <tr>
    			<td>Name:</td>
    			<td><input name="name2" type="text" size="50"></td>
    		  </tr>
    		  <tr>
    			<td valign="top">Street:</td>
    			<td><textarea name="address2" cols="65" rows="5"></textarea></td>
    		  </tr>
    		  <tr>
    			<td>City:</td>
    			<td>
    			<input name="city2" type="text" size="35"> <label for="state2">State:</label> <select name="state2">
    			  <option selected>State</option>
    			  <option>AL</option>
    			  <option>AK</option>
    			  <option>AZ</option>
    			  <option>AR</option>
    			  <option>CA</option>
    			  <option>CO</option>
    			  <option>CT</option>
    			  <option>DE</option>
    			  <option>DC</option>
    			  <option>FL</option>
    			  <option>GA</option>
    			  <option>HI</option>
    			  <option>ID</option>
    			  <option>IL</option>
    			  <option>IN</option>
    			  <option>IA</option>
    			  <option>KS</option>
    			  <option>KY</option>
    			  <option>LA</option>
    			  <option>ME</option>
    			  <option>MD</option>
    			  <option>MI</option>
    			  <option>MN</option>
    			  <option>MS</option>
    			  <option>MO</option>
    			  <option>MT</option>
    			  <option>NE</option>
    			  <option>NV</option>
    			  <option>NH</option>
    			</select> <label for="zip2">Zip</label> <input name="zip2" type="text" size="10">
    			</td>
    		  </tr>
    		</table>
    
    		</fieldset>
    And this is the JS I have:

    Code:
    function sameischecked() {
    		obj.name2.value = obj.name.value;
    		obj.address2.value = obj.address.value;
    		obj.city2.value = obj.city.value;
    		obj.state2.selectedIndex = obj.state.selectedIndex;
    		obj.zip2.value = obj.zip.value;
    }
    --
    sethtrain

  4. #4
    SitePoint Addict Guimauve's Avatar
    Join Date
    Aug 2004
    Location
    Chicago
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I assume that obj is the name of your form?? If not then what is it and where is it initialized. If it is the name of your form add document. in front of obj like document.obj.

    Charles


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •