views:

1549

answers:

2

Hi all,

I have a jQuery script that will display specific divs depending on which select option has been selected.

Here's the code for that:

jQuery.noConflict();
jQuery(document).ready(function() {
  jQuery.viewMap = {
    '' : jQuery([]),
    '1' : jQuery('.company_1'),
    '2' : jQuery('.company_2')
  };
  jQuery('#companyid').change(function() {
    jQuery.each(jQuery.viewMap, function() { this.hide(); });
    jQuery.viewMap[jQuery(this).val()].show();
  });
});

(example div)

<div class="company_1" style="display: none;">
  <input type="checkbox" name="classifications[Miner]" id="classifications[Miner]" /> Spec/Rough
  <input type="checkbox" name="classifications[Dealer]" id="classifications[Dealer]" /> Dealer
</div>

I'd like it to clear all the checkboxes inside the div (.company_1, .company_2 etc) if someone selects a different option. If that makes sense? :)

Thank you!

+6  A: 

Unchecking a checkbox is achieved by removing the attribute named "checked". Try:

jQuery.each(jQuery.viewMap, function() {
    this.hide();
    jQuery('input:checkbox', this).removeAttr('checked');
});
Ken Browning
Thanks so much, works perfectly! :)
SoulieBaby
+1  A: 

How about:

$("div.company_1 input[type:checkbox]").removeAttr("checked");
David Andres