DEVFYI - Developer Resource - FYI

How to find the selected radio button immediately using the 'this' variable?

JavaScript Interview Questions and Answers


(Continued from previous question...)

73. How to find the selected radio button immediately using the 'this' variable?

<script>
function favAnimal(button) {
alert('You like '+button.value+'s.');
}
</script>
<input type="radio" name="marsupial" value="kangaroo"
onchange="favAnimal(this)">Kangaroo
<br /><input type="radio" name="marsupial" value="Opossum"
onchange="favAnimal(this)">Opossum
<br /><input type="radio" name="marsupial" value="Tasmanian Tiger"
onchange="favAnimal(this)">Tasmanian Tiger

(Continued on next question...)

Other Interview Questions