manisha manisha - 2 years ago 73
Javascript Question

Jquery get id of radio button by testing value

I have a read only form that I want to populate the values returned from an ajax query. What I don't understand is the correct syntax to get the id of a specific radio button. I know what value exists in the db, but how to get the id of the radio button, to change the radio button attribute?

For example, in the Radio Button options with the "name"==Criteria1Score", how to I return the id of the input where value ==Good.

Here is an example of the form structure:

<label class="radio inline">
<input id="Criteria1Score1" class="Score" name="Criteria1Score" type="radio" value="Great">
<label class="radio inline">
<input id="Criteria1Score2" class="Score" name="Criteria1Score" type="radio" value="Good">
<label class="radio inline">
<input id="Criteria1Score3" class="Score" name="Criteria1Score" type="radio" value="Bad">

Answer Source


See fiddle example

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download