开发者

Radiobuttonlist? When I select a radiobutton I want to unselect by clicking again the selected radio button

I use asp:radiobuttonlist and have 2 radio's, e.g. YES / NO.

I want to able to give the user the ability to undo a selection after they clicked YES or NO, by clicking YES or NO again.

For example, a user clicks on YES but he thinks "no, I will answer this later". They can't undo the selection... They must choose YES or NO.

开发者_JS百科

Is there a way to make it so that when the user clicks on YES, yes is selected and when they click YES again, it should be unselected... The outcome should be that yes and no are not filled/clicked/selected?

I don't want to add a 3rd radio button as an option. just want to able to give the user functionality so that when he clicks again on a selected item, it should be unselected... Desired result: Both are unselected.

I need to think in the direction of jQuery, right?


This isn't the expected behaviour of a radiobutton - you don't click it again to negate it. If you want that you should look at checkbox/checkboxlist.


You could give them a third "undecided" radio button? As shown in this fiddle.


think outside the box. Use a label like 'Include this?' with a checkbox that we they can check and uncheck to their hearts desire Mostly gui questions like this are about the right approach.


Use a checkboxgroup and bind click handler to deselect the others of that group:

$("input[type='checkbox']").bind('click', function() {
    var name = $(this).attr('name');
    $("input[type='checkbox'][name='" + name + "'][id!='" + $(this).attr('id') + "']").map(function() {
        $(this).prop('checked', false); return this;
    }).checkboxradio('refresh');
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜