0

I have the following filter setup:

<div class="element">
<input type="radio" name="group1" value="1">
<input type="radio" name="group1" value="2">
<input type="radio" name="group1" value="3">
</div>

<div class="element">
<input type="radio" name="group2" value="1">
<input type="radio" name="group2" value="2">
<input type="radio" name="group2" value="3">
</div>

And I'm using the following to select the first radio buttons automatically:

$('.element').each(function(){
    $('input[type=radio]', this).get(0).checked = true;
});

The problem is, even though the first radio buttons are selected, the filter I'm using isn't reflecting those selections because it's using an onChange event. So, when the first radio buttons are checked (on load), how can I have them trigger a change event so the filter will function?

Any ideas?

Jonas
  • 121,568
  • 97
  • 310
  • 388
blicht454
  • 29
  • 1
  • 9
  • 1
    Call your filter function directly. `change` events are only triggered when the user changes an input, not when it's changed by code. – Barmar Jul 19 '13 at 16:45
  • See this question http://stackoverflow.com/questions/871063/how-to-set-radio-option-checked-onload-with-jquery – user568109 Jul 19 '13 at 16:54

1 Answers1

2

The change handler will be called when you trigger a click event instead:

$('.element').each(function(){
    $('input[type=radio]', this).first().click();
});
Martin Dow
  • 5,273
  • 4
  • 30
  • 43