I have a form with radio buttons:
<ul class='likert'>
<li>
<input type="radio" name="q1" value=5 required>
</li>
<li>
<input type="radio" name="q1" value=4>
</li>
<li>
<input type="radio" name="q1" value=3 checked="checked">
</li>
<li>
<input type="radio" name="q1" value=2>
</li>
<li>
<input type="radio" name="q1" value=1>
</li>
</ul>
In Firefox and Chrome,
parseInt(document.forms["question_form"]["q1"].value)
returns 3 (or whatever) but in Internet Explorer I get ‘NaN’.
In JavaScript, NaN stands for Not a Number. It represents a value which is not a valid number. It can be used to check whether a number entered is a valid number or not a number.
In JavaScript, NaN is short for "Not-a-Number". In JavaScript, NaN is a number that is not a legal number. The Global NaN property is the same as the Number.
NaN is an error value that means not a number. However, JavaScript considers the type of NaN to be number. Infinity is a value so big it can't be represented by JavaScript numbers.
IE returns a HTMLCollection when the names are not unique in document.forms["question_form"]["q1"]
.
See Remarks at IHTMLElementCollection
"If duplicate names are found, a collection of those named items is returned."
You can get the checked value for example like this:
var val = document.querySelector('.likert input:checked').value);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With