I have a strange behaviour with my js code. I do a JsFiddle here : http://jsfiddle.net/wf8G6/2/
I want to update the "option selected" of a select when I check a particular checkbox...
Actually I have to click 3 times to trigger the event...
I check the checkbox => nothing happens I uncheck the checkox => nothing happens I check the checkbox => it works ...
Here is my HTML
<fieldset class="attribute_fieldset" rel="">
<input class="left cb_group_5" type="checkbox" value="group_5" />
<select name="group_5" id="group_5" class="attribute_select hidden">
<option value="23" selected="selected" title="non">non</option>
<option value="24" title="oui">oui</option>
</select>
</fieldset>
Here is my JS
//if we check a checkbox, we trigger a click on the select below
$('.attribute_fieldset input[type=checkbox]').change(function () {
var target = '#' + $(this).val();
$(target + ' option').removeAttr('selected');
if (this.checked) {
$(target + ' option[title="oui"]').attr('selected', 'selected');
} else {
$(target + ' option[title="non"]').attr('selected', 'selected');
}
$(target).trigger('change');
});
What I do wrong ? Please, help me community =)