How can I check which of the two radio button is checked in javascript/jquery in order to get the value of the input considering the fact that, in the HTML, both of them are by default unchecked (no checked attribute is added)
<input type="radio" name="AS88" value="true" required>
<input type="radio" name="AS88" value="false">
The following code does not work:
var elements = document.getElementsByName("AS88");
for (var i=0, len=elements.length; i<len; ++i) {
if (elements[i].checked) {
alert(elements[i].value)
}
};
EDIT:
Solutions with :checked
in jquery such as:
$('input[name="AS88"]:checked').val();
always return undefined