Take the 2-minute tour ×
$("#poll1p").append("<input type='radio' name='radio1' id='r1' /><label for='radio1'>"+x[0]+"</label><br>");
$("#poll1p").append("<input type='radio' name='radio1' id='r2' /><label for='radio1'>"+x[1]+"</label><br>");

the values x[0] and x[1] are array values. I am not able to get the selected radio button value by using


If i use the above,i just get "ON" as a return value... I need the value from

share|improve this question
Could we see your html and where you are trying to get the radio button's value and why? There isn't enough information here to be helpful. –  Becuzz Feb 4 '11 at 20:04
html is a very big file ... I cant add it completely ... What i am doing is , i get the labels for radio buttons from the database based on some criteria and i display it as a form. –  Newbie Feb 4 '11 at 20:26

2 Answers 2

up vote 7 down vote accepted

You need to specify a value="..." attribute for your radio buttons if you want some value besides "on" returned.

Use the following, and you should get back 1 or 2 from .val():

<input type='radio' name='radio1' id='r1' value="1" />
<input type='radio' name='radio1' id='r2' value="2" />

Not related, but you also need to use for="r1" and for="r2" for your lables - ie, use an element's id as the value of the for attribute of its label.

share|improve this answer
can i put a javascript variable as the value for "value" attribute ... ?? –  Newbie Feb 4 '11 at 20:16
@hari No, but you can can use JS to dynamically assign values to each radio button based on ID when the document loads. –  meagar Feb 4 '11 at 20:24

You need to put a value='' attribute on the radio buttons you are appending.

share|improve this answer

Your Answer


