Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting form verification just sometimes... 1

Status
Not open for further replies.

leadman

Programmer
Joined
Jun 11, 2001
Messages
177
Location
US
okay - you know how when you go to buy something online and you enter your billing info and then there is a section to input the shipping info. Nice sites let you do someting like check a box called "same as billing" if the two are the same so you dont have to reinput everything.
Im trying to get that effect but it has caused the following predicament: i have one form collecting billing and shipping info - in the middle of the form i have a checkbox called "same as billing". The action template recognizes if this is checked and simply assigns the billing values to the shipping fieldnames. The problem is this - on the form page, im using cfform elements to validate several of the billinng info fields BUT i cant use them on the shipping part of the form since, if the user checks "same as billing", it will stop the process and make the user enter shipping anyway.
Is there a way to tell the second half of the form to veriry only if the box in the middle of the same form is not checked?
 
you can use the following script to determine if the checkbox is checked or not and based on that you can execute the validation or not...

<script>
function checkTheBox(){
if (document.memberCheckForm.sameAsBilling.checked){
alert(&quot;The &quot;+document.memberCheckForm.sameAsBilling.name+&quot; checkbox is checked&quot;)
}else{
alert(&quot;The &quot;+document.memberCheckForm.sameAsBilling.name+&quot; checkbox is NOT checked&quot;)
}
}
</script>

<form action=&quot;test.cfm&quot; enctype=&quot;multipart/form-data&quot; method=&quot;post&quot; name=&quot;memberCheckForm&quot;>
<input type=&quot;checkbox&quot; name=&quot;sameAsBilling&quot; onclick=&quot;checkTheBox()&quot;>
</select>
</form> Sylvano
dsylvano@hotmail.com
 
this test makes an alert box come up, then? Do i replace the alert box script with script that validates the form fields? could you show me what that would look like?
 
the checkTheBox() function is called and executed on onclick event(or whenever user click on it), therefore, the check box can have only two states: checked or unchecked;

the: &quot;if (document.memberCheckForm.sameAsBilling.checked)&quot;
part will return true if the sameAsBilling checkbox is checked, therefore, we have same shipping address as billing (that is all ready entered and verified);
so, in this case we don't have to execute the verification, but rather just to populate the rest of the form (if necessary);

to do that you can replace the alert part with the code that will populate the shipping Address text field; if the billing address is allready entered and verified, when &quot;same as billing&quot; field is checked, the shipping address text field will dynamically populate it self by taking the value of the billing Address text field:

<script>
function checkTheBox(){
if (document.memberCheckForm.sameAsBilling.checked){
document.memberCheckForm.shippingAddress.value = document.memberCheckForm.billingAddress.value
}else{
document.memberCheckForm.shippingAddress.value = &quot;&quot;
}
}
</script>

<form action=&quot;test.cfm&quot; enctype=&quot;multipart/form-data&quot; method=&quot;post&quot; name=&quot;memberCheckForm&quot;>

<input type=&quot;text&quot; name=&quot;billingAddress&quot; value=&quot;1550 s 20 av.&quot;>Billing Address<br>
<input type=&quot;checkbox&quot; name=&quot;sameAsBilling&quot; onclick=&quot;checkTheBox()&quot;>Same as billing<br>
<input type=&quot;text&quot; name=&quot;shippingAddress&quot;>Shipping Address
</select>
</form> Sylvano
dsylvano@hotmail.com
 
im trying it now - my test has biven an error in the browser - it says:
'document.memberCheckForm.sameaddress' is not an object.
'sameaddress' is the name of the checkbox. My form spans two tables, could that be the problem?
 
possible but i can't say until i see it; try pasting the code i posted here in the separate template and test it. that might help you to narrow the problem down; Sylvano
dsylvano@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top