I recently came across a StackOverflow answer that gave excellent instructions on how to get the value of a checked radio button using jQuery:
var radioVal = $("#myFormID input:radio[name='radioFieldName']:checked").val();
alert('Selected radio button value = ' + radioVal);
Now I'm trying to find the zero-based index of the checked radio button. I thought it would be relatively simple:
var radioIdx = $("#myFormID input:radio[name='radioFieldName']:checked").index();
However, radioIdx
is always returning a value of -1
. Any ideas on what I might be doing wrong?