I have a HTML form with radio inputs and want to use javascript to analyse the results.
I am getting stuck at retrieving the form information in my JavaScript function:
function getResults(formInput){
alert (formInput.question1);
}
Where question1 is the “name” of my radio button group.
This returns “object Nodelist” and I haven’t a clue what’s wrong, I would expect it to return “1”, which is the value of my radio button when selected.
I don’t want to work out which radio button is selected and which isn’t, I need to know the value associated with the selected radio button.
The
object Nodelistthat you’re referring to is being returned because you have a group of elements that share the same name. If you want to see the value of the radio button that’s checked, you need to loop through the collection:Here’s a working jsFiddle.