Issue
I have created input-type checkbox fields like below:
<input type="checkbox" class="" value="1" name="foo" />
<input type="checkbox" class="" value="1" name="foo" />
<input type="checkbox" class="" value="1" name="foo" />
Now i want checkbox work as radio button like single select. so using jquery is working fine:
$("input:checkbox").click(function(){
var group = "input:checkbox[name='"+$(this).prop("name")+"']";
$(group).prop("checked",false);
$(this).prop("checked",true);
});
But now if i want to reverse that checkbox work as checkbox using jquery then not working.
Solution
This is possible, but but you really shouldn't do it. It will lead to a poor user experience, because a user will generally assume that a set of checkboxes means they can select more than one if they wish to. If they see radio buttons, they know they have to make a single choice. If they find a checkbox set where they can't select more than one, it might be frustrating and they may even think there is a bug in your application.
Also, why would you need to "re-enable" anything? Once the question is answered, you would render a new question instead. You wouldn't re-use the same markup for a new question...that doesn't make any sense.
Instead, when rendering each question, make your code (either client-side or server-side, as per your rendering architecture) generate either checkboxes or radio buttons, as appropriate, depending on whether your database indicates that the question requires multiple or single answers. This should be both simpler than solutions which manipulate the checkbox behaviour, and will lead to a better UI.
Answered By - ADyson
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.