<...">

Getting the value of the selected switch

$("#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 the values ​​of the array. I cannot get the selected switch value with

$("input:radio[name='radio1']:checked").val();

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

+3
source share
2 answers

You need to specify an attribute value="..."for your switches if you want to return some value other than "on".

Use the following and you must return to 1or 2from .val():

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

Not relevant, but you also need to use for="r1"it for="r2"for your tables too - i.e. use an element idas the attribute value of forits label.

+7

value = '' .

+1

Source: https://habr.com/ru/post/1790066/


All Articles