I need to obtain which radio button is checked using plain javascript ( No JQuery ) without looping through each input elements and checking for ‘checked’ attribute for each.
PS : Jquery solution would also be appreciated 🙂
Given HTML :
<tr id = "reportLayout">
<th align="left" style="padding-right: 10px">Layout</th>
<td>
<input type="radio" name="layout" value="portrait">Portrait</input>
<input type="radio" name="layout" value="landscape">Landscape</input>
</td>
</tr>
OK, use the
:checkedselector:Where the value of the checked radio would be:
To do it without jQuery the “standard” way to do it is with a loop, but you could also do this if you don’t care about IE < 9:
Demo: http://jsfiddle.net/xHAwX/1/