user979331
user979331

Reputation: 11851

jQuery populate radio buttons

I have this radio button:

<td><input type="radio" name="training" value="yes"> Yes &nbsp; <input type="radio" name="training" value="no"> No</td>

And I am getting a data from a database via ajax call. The training value from the database is either yes or no.

My question is, how would I populate the radio buttons based off the value from the database.

Upvotes: 0

Views: 1991

Answers (1)

Ibrahim Khan
Ibrahim Khan

Reputation: 20740

You can check radio button with value like following.

var valueFromDB="yes"; //assume this is your value from DB.
$('input[name=training][value=' + valueFromDB + ']').prop('checked', true);

Hope this will help you.

Upvotes: 1

Related Questions