I have a pair of radios, to which I assign a function using bind(), on the pages .ready event. then, on the same ready event, I check for another input's value, and if it's value is "1" I preselect the second radio button when the page loads. here is a snippet.
<input type="radio" name="fpago" id="fpago1" value="1" />one
<input type="radio" name="fpago" id="fpago2" value="2" />two
...
$(document).ready(function() {
$("#myspan").hide();
$("#fpago1, #fpago2").bind('change click',function(){
togglePlazo();
});
//initial condition to preselect radio #2
grupo = $("#id_grupo").val();
if(grupo != '0'){
$("#fpago2").attr('checked', true); //checks the radio, but doesn't trigger function
}
});
...
--> see here for a more complete code
The problem is that, the radio does get checked if the condition is met, BUT the bound function togglePlazo()
doesn't trigger...
If later I manually click the radio buttons, the function does get triggered, and the span toggles. It is only on the initial "check" made with jQuery, where the function does not trigger despite the radio getting changed.
I don't know what I'm missing, maybe I should bind more events other than change or click... I just can't find what I am doing wrong.
NOTE: I am using jQuery 1.4.2, but the fiddle is set to use 1.6.4 (it doesn't have 1.4.2 as an option)