3

I would like to show a modal dialog if a person select "No". And it works but I also need to keep selected answer "No".

So after I close modal window radio button not selected. Any ideas how to fix it?

here is my code:

$(function() {
                $('#btnNext').attr('disabled', true);
                $('input[type="radio"]').change(function(e) {
                    var $yes = $('input[type="radio"][value="Yes"]');
                    var $no = $('input[type="radio"][value="No"]');
                    if ($yes.filter(':checked').length === $yes.length) {
                        $('#btnNext').attr('disabled', false);
                    } else {
                        $('#btnNext').attr('disabled', true);

                        var $nope = $(this).attr("name");
                        var $value = $(this).attr("value");
                     if ($value === "No") {
                       $(this).attr("checked", "checked"); // $(this).attr("checked", true);    
                            $('#' + $nope).dialog('open');
                     }
                    }
                });
        });
Michael Born
  • 799
  • 3
  • 15
  • 28

3 Answers3

0

Opening modals seems to prevent the default radio selection event from completing. Try deferring the opening of the modal until after the radio event has finished:

setTimeout(function() {
    $('#' + $nope).dialog('open');
}, 1);
Brett
  • 2,706
  • 7
  • 33
  • 49
0

$("#ynRadion").prop("checked", false);

$("#ynRadioy").prop("checked", false);

<input type="radio" name="ynRadio" id="ynRadion" class="radioBtn" value="no" />

<input type="radio" name="ynRadio" id="ynRadioy" class="radioBtn" value="yes" />
0
$("#radioSelector").checked = false; 

But this is a duplicate of: How to uncheck a radio button?

Update

Sorry try this:

$(function() {
    $('#btnNext').attr('disabled', true);
    $('input[type="radio"]').change(function(e) {
        if ( $(this).is(":checked") && $(this).val() == "No"){
            var $nope = $(this).attr("name");
            $('#' + $nope).dialog('open');
        }
    });
});
Community
  • 1
  • 1
locrizak
  • 12,192
  • 12
  • 60
  • 80
  • It's not working. I need to select clicked radio button and show modal dialog. but it's only shows dialog. And in my example I tried the same code and it's not working – Michael Born May 13 '11 at 15:47
  • 2
    no it's not working. The same shows dialog window but radio button unchecked – Michael Born May 13 '11 at 15:57