Reputation: 2420
When I'm clicking on the cancel button I need to clear entered or selected values in controls (textboxes, checkboxes, and radio button).
Unfortunately the checkbox and radiobutton selected values not getting changed on cancel btn click and textbox values are cleared.
The controls are in div having id divUser
. How can I clear the checkboxes selection and radio button?
$("#btnCancel").click(function () {
$('input, select,input:radio', $('#divUser')).val('');
});
Upvotes: 0
Views: 385
Reputation: 5655
$("#btnCancel").click(function () {
$('input', $('#divUser')).val('');
$('select,input:radio', $('#divUser')).attr('checked', false);
});
trick here is change checked attribute instead of value.
Upvotes: 0
Reputation: 17118
To unselect or uncheck radio buttons and checkboxes you need to remove the checked
attribute:
$("input:radio,input:checkbox").removeAttr('checked');
Upvotes: 1
Reputation: 27364
Try
$("#btnCancel").click(function ()
{
$('input, select,input:radio,#divUser').val('');
});
Upvotes: 0