...

View Full Version : script for bill same as ship info



mrsh
09-03-2010, 05:24 PM
I have a form & I want the customer to be able to check a box if the bill to information is the same as the ship to information & have the information automaticlly put into the appropriate boxes. I have the following script in the head of my html page:

<script language="JavaScript">
<!--
function shipsame()
{
var form = document.forms[0];
if(form.sameasbilling.checked){

form.shipname.value = form.shipname.value;
form.shipaddress.value = form.billaddress.value;
form.shipaddress2.value = form.billaddress2.value;
form.shipcity.value = form.billcity.value;
form.shipstate.value = form.billstate.value;
form.shipzip.value = form.billzip.value;
form.shipcontact.value = form.billcontact.value;
form.shipphone.value = form.billphone.value;

}else{

form.shipname.value = "";
form.shipaddress.value = "";
form.shipaddress2.value = "";
form.shipcity.value = "";
form.shipstate.value = "";
form.shipzip.value = "";
form.shipcontact.value = "";
form.shipbill.value = "";

}
}
function fixup() {
var cb = document.forms[0].sameasbilling;
cb.onclick = shipsame;
}
function MM_callJS(jsStr) { //v2.0
return eval(jsStr)
}
//-->
</script>

And I have the following in my form section:

<input name="sameasbilling" type="checkbox" onclick="MM_callJS('sameasbilling')" value="yes" onload="fixup()"/>

I am not a programmer & have gotten this script from searching the web. I have tried several things but do not know enough to fix the problem. I'm not even sure if the ship or bill should come first in the code. The customer will be filling out the bill to information first on my form. I would appreciate any help but please put it in VERY simple terms that I can understand.
Thank you:)

Old Pedant
09-03-2010, 08:22 PM
I *think* all you need to do is change the bogus checkbox code.

Try this:


<input name="sameasbilling" type="checkbox" onclick="shipsame()" value="yes" />


And GET RID of the two useless functions:

function fixup() {
var cb = document.forms[0].sameasbilling;
cb.onclick = shipsame;
}
function MM_callJS(jsStr) { //v2.0
return eval(jsStr)
}


And stop using <!-- and --> in your <script> blocks, unless you are worried about supporting MSIE version 3 (you know, the one that was obsolete by 1998).

Old Pedant
09-03-2010, 08:24 PM
I should note that if the user checks the checkbox *BEFORE* filling in the billing address, then of course nothing will be copied. So you want to *ALSO* call the shipsame() function as part of your <form onsubmit=...> coding.

mrsh
09-03-2010, 09:17 PM
I tried it & it worked beautifully!! Thank you so much for taking the time to help me & for making the explanation easy for me to understand. I am not a programmer but I have a small business & try to do my best to maintain a web site. I reeeeally appreciate any & all help!!!:thumbsup:

Philip M
09-04-2010, 09:10 AM
I should note that if the user checks the checkbox *BEFORE* filling in the billing address, then of course nothing will be copied. So you want to *ALSO* call the shipsame() function as part of your <form onsubmit=...> coding.

It might be a good idea to disable the checkbox until the billing address details have ben filled in.

mrsh
09-04-2010, 05:52 PM
I don't think I need to disable the checkbox or use the sameship() function either because of the way I set up the form. It is a quote form & it has three sections. The first is the billing section & that information is *REQUIRED. After they fill that in the next section is the ship information but right at the top of the ship info is the checkbox CHECK HERE IF SHIP INFO IS SAME AS BILL INFO. So if they check the box then the ship info is automaticlly filled in for them or if they don't they can fill it in or leave it blank. It's not required. And then the last section is the quote section. So I think I'm good but I do REALLy appreciate all your help.:D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum