JQuery radio headaches
I have 2 radio stations:
<input id="a_15_0" type="radio" value="abc" name="a_15"/>
<input id="a_15_1" type="radio" value="xyz" name="a_15"/>
Both are not selected. I only have the name of the radio, i.e. a_15
but not identifiers.
1) How can I get the value of the selected option of this radio? For example, if the user clicked "xyz", how can I get it? I am currently using:
var val=$('[name="a_15"]').val();
which always gives abc even when xyz is selected.
2) How can I get the xyz to select via javascript without knowing the id of the radio station that xyz says? Performance:
$ ('[name = "a_15"]') Val ('XYZ') ;.
Changes the value of both radios to xyz rather than fetching the value that was xyz.
Do I need to use document.myForm.a_15.value
? Will this work consistently?
source to share
1) try
var val = $('input[name=a_15]:checked').val();
jQuery docs on tested pseudo-class
2) the only solution found is
$('input[name=a_15][value=xyz]').get(0).checked=true
source to share