Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
111
rated 0 times [  118] [ 7]  / answers: 1 / hits: 26167  / 12 Years ago, sat, july 28, 2012, 12:00:00

Possible Duplicate:

how to check a radio button with jQuery?




How to change a radio button value.


jQuery('input:radio[name=search][id=search-damages]').checked = true;

i have tried this but it is not working


<input type="radio" name="search" id="search-vehicle" value="search-vehicle" checked>
<input type="radio" name="search" id="search-damages" value="search-damages">

More From » jquery

 Answers
184

How to change a radio button value?



checked property doesn't change the value of radio button. note that checked property is one the DOM INPUT Element properties and not one of the jQuery object properties(by selecting an element using jQuery, a jQuery object is created). If you want to change this property you should first convert the jQuery object into a DOM Element object.


$('#search-damages')[0].checked = true;

or use the jQuery object's prop() method:


$('#search-damages').prop('checked', true)

If you want to change the value of an input you can use the jQuery val() method:


$('#search-damages').val('new value');

[#84011] Thursday, July 26, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
carolyn

Total Points: 618
Total Questions: 119
Total Answers: 86

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;