user2156088
user2156088

Reputation: 2420

Checkboxes and radio button selected values not getting cleared using Jquery

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

Answers (3)

rahul maindargi
rahul maindargi

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

von v.
von v.

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

Dipesh Parmar
Dipesh Parmar

Reputation: 27364

Try

$("#btnCancel").click(function ()
{
   $('input, select,input:radio,#divUser').val('');
});

Upvotes: 0

Related Questions