Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Sep 2010
    Posts
    12
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Smile script for bill same as ship info

    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

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    I *think* all you need to do is change the bogus checkbox code.

    Try this:
    Code:
    <input name="sameasbilling" type="checkbox" onclick="shipsame()" value="yes" />
    And GET RID of the two useless functions:
    Code:
    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).
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    mrsh (09-03-2010)

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    mrsh (09-03-2010)

  • #4
    New Coder
    Join Date
    Sep 2010
    Posts
    12
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Smile Thank you, Thank you, Thank you!

    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!!!

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,914
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by Old Pedant View Post
    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.

  • #6
    New Coder
    Join Date
    Sep 2010
    Posts
    12
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

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