mardi 5 mai 2015

How to revert radio button checked change?

I have a .change() placed for each radio button in table:

    for (var i = 0; i < Count; i++) {
        $('input[name="Options[' + i + '].Completed"]').change(function () {
            var number = $(this).attr("name").match(/\d+/g)[0];
            ...
            some action
            ...
        });
    }

What I'm tryin to do is to revert radio botton change in case of some condition.

By default, my radiobutten is marked as false (Yes No, No by default). If I clicked to Yes, but don't mach the condition, I need to stay on No.

I have tried to do this in this way:

if (... condition ...) {
     $('input[name="Options[' + i + '].Completed"]').filter('[value=False]').prop('checked', true);
}

But this doesn't seems to work (nothing happened, but condition works fine).

What am I doing wrong and how can I accomplish my goal?

EDIT:

radiobutton html:

<input id="Options_0__Completed" name="Options[0].Completed" type="radio" value="True" style="position: absolute; z-index: -1; opacity: 0; margin: 0px; padding: 0px;">
<input checked="checked" id="Options_0__Completed" name="Options[0].Completed" type="radio" value="False" style="position: absolute; z-index: -1; opacity: 0; margin: 0px; padding: 0px;">

Aucun commentaire:

Enregistrer un commentaire