tags:

views:

52

answers:

2

I have the following Radio Buttons:

         <form id="bg" action="#">
            <span id="questionText">Question Test Here:</span><br/>
            <input type="radio" name="bga"><span id="A1"></span></input><br/>
            <input type="radio" name="bga"><span id="A2"></span></input><br/>
            <input type="radio" name="bga"><span id="A3"></span></input><br/>
            <input type="radio" name="bga"><span id="A4"></span></input><br/>
            <input type="button" name="btn" id="btn" value="OK!"/>
         </form>

I want to be able to set the values of each individual radio button with a different value using jQuery.

+2  A: 
var i=0;
$(':radio', $('#bg')[0]).each(function() {
  $(this).attr('value', i++).text("Option " + i);  // value=0, text="Option 1", etc.
});
Yanick Rochon
@Yanick Can you expand your example to set the text of the radio button and the value for each button?
Jeff V
done! You will notice that, in this example, the value is from 0-n, while the text is "Option 1" to "Option n+1" because the i is incremented when setting the value attribute. Of course, this is only an example, you can set whatever value you want, and whatever text you wish...
Yanick Rochon
Thank you very much!
Jeff V
A: 

You can give each radio element an id then $("#id").attr("value", "thevalueyouwant") for each one.

Roy Tang
This one worked for my situation!
Jeff V