Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a checkbox to toggle the display of a page element (IE7 problems!)

When users check the "My shipping address and billing address are the same" checkbox, I want to hide the shipping address form.

This code works well in everything except IE:

$("#order_shipping_same_as_billing").change(function() { 
  $("fieldset.shipping").toggle("blind", { 'direction' : 'vertical' }, 50);
});

IE doesn't register the change event until the checkbox loses focus, which makes for an unpleasant user experience.

Many shopping sites (and non-shopping sites!) do stuff like this -- there must be a cross-browser compatible method that I'm missing.

like image 873
Tom Lehman Avatar asked Feb 03 '26 04:02

Tom Lehman


1 Answers

I usually use the click event for checkboxes instead of change. That way it works in IE as well.

$("#order_shipping_same_as_billing").click(function() { 
  $("fieldset.shipping").toggle("blind", { 'direction' : 'vertical' }, 50);
});
like image 148
slosd Avatar answered Feb 05 '26 07:02

slosd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!