mardi 16 janvier 2018

Uncheck checkbox if another is selected

So i have the following 2 checkboxes on my page on small script attached to it which is designed to hide the billing section.

<script>

function myFunction2() {
    var x = document.getElementById("billing_info");
    if (x.style.display === "none") {
        x.style.display = "block";
    } else {
        x.style.display = "none";
    }
}

</script>

    <div class="header">
       <h3 class="checkout-headers">STEP 3 - Billing Information </h3>
      <!--START: sameAsBilling1-->
<!--value="ON"-->
      <div class="sameAsBilling1">
        <input type="checkbox" name="sameAsBilling" id="sameAsBilling" onclick="showHideShipping();check_address('');"/>
        <label for="sameAsBilling">Same as Delivery Address</label>
        <div class="clear"></div>
      </div>
        <div class="differentBilling">
            <input type="checkbox" class="example" onclick="myFunction2()"; return false;>Different Billing Address?</div>
      <!--END: sameAsBilling1-->
      <div class="clear"></div>
    </div>

My problem is someone as buried the following code in a javascript file which is what transfers the delivery details onto the billing details if the specific checkbox is ticked.

function showHideShipping() {

  if (get_Element('sameAsBilling') != 'undefined' && get_Element('sameAsBilling') != null) {
    if (document.billing.sameAsBilling.checked) {
      add_overlay("billing_info", 0);

      get_Element('billing_firstname').value = '';
      get_Element('billing_lastname').value = '';
      get_Element('billing_company').value = '';
      get_Element('billing_phone').value = '';
      get_Element('billing_address').value = '';
      get_Element('billing_address2').value = '';
      get_Element('billing_city').value = '';
      get_Element('billing_zip').value = '';
      get_Element('billing_country').value = get_Element('shipping_country').value;
      populateState('billing_state', 'billing_country');
      get_Element('billing_state').value = get_Element('shipping_state').value;
    } {
      remove_overlay("billing_info");

      if (get_Element('billing_firstname').value != get_Element('shipping_firstname').value) {
        get_Element('billing_firstname').value = get_Element('shipping_firstname').value;
        get_Element('billing_lastname').value = get_Element('shipping_lastname').value;
        get_Element('billing_company').value = get_Element('shipping_company').value;
        get_Element('billing_phone').value = get_Element('shipping_phone').value;
        get_Element('billing_address').value = get_Element('shipping_address').value;
        get_Element('billing_address2').value = get_Element('shipping_address2').value;
        get_Element('billing_city').value = get_Element('shipping_city').value;
        get_Element('billing_zip').value = get_Element('shipping_zip').value;
        get_Element('billing_country').value = get_Element('shipping_country').value;
        populateState('billing_state', 'billing_country');
        get_Element('billing_state').value = get_Element('shipping_state').value;
      }
    }
  } else {
    //add_overlay("shipping_info",0);
  }
}

I've followed the code from the following jsfiddle.

http://ift.tt/2DjWFaK

But that stops the same as delivery button from working correctly.




Aucun commentaire:

Enregistrer un commentaire