views:

51

answers:

2

I need to fire the change event when other javascript function changes the checked status. Simplified code below. I can not call MyFunc() from MyOtherFunc().

jQuery:

$(document).ready(function(){
  $('input:radio[name=rdName]').change(function(){
    MyFunc();
  });
});
function MyFunc(){
  //do stuff
}
function MyOtherFunc(){
  $('input:radio[name=rdName]')[0].checked = true;
  // Was unable to have it change based on a value
}

Radio buttons:

<input type="radio" name="rdName" value="1">
<input type="radio" name="rdName" value="2">
<input type="radio" name="rdName" value="3">
+3  A: 
$(document).ready(function(){
  $('input:radio[name=rdName]').change(function(){
    MyFunc();
  });
});
function MyFunc(){
  //do stuff
}
function MyOtherFunc(){
  $('input:radio[name=rdName]').attr('checked', 'checked').trigger('change');

}
jAndy
+2  A: 
 $('input:radio[name=rdName]').change();
Tgr
+1 Deleted my answer after rereading the question, and realizing it was specifically about firing an event.
patrick dw
This is the trick!
Gutzofter