Behnam8
Behnam8

Reputation: 65

Clearing a form inputs except some controls

I have a panel named pBody and I can clear its controls by using these codes. clear all textboxes, uncheck radio buttons and checkboxes:

$('#pBody input').val('');

clear only textboxes:

$("#pBody").find("input[type=text]").val(''); 

or

$("#pBody").find("input:text").val('');

But after clicking clear button I want make some radio buttons checked, for example first radio buttons in the group. Thanks in advance.

Upvotes: 0

Views: 52

Answers (2)

Jegan
Jegan

Reputation: 595

For check the first radio button as default you can use the below code

$('#pBody').find('input:radio').first().prop({checked:true});

or

$('#pBody').find('input:radio').first().attr({checked:true});

and for checkboxes use

$('#pBody').find('input:checkbox').first().prop({checked:true});

or

$('#pBody').find('input:checkbox').first().attr({checked:true});

Upvotes: 0

शेखर
शेखर

Reputation: 17614

You can use input[type=radio]:first selector to select first radio-button in the list.
Or if you want that every gruop first radio button get selected you can use

$('element').each(function(){
    $('input[type=radio]:first', this).attr('checked', true);
});

Upvotes: 1

Related Questions