Basic JavaScript Question:

Download Job Interview Questions and Answers PDF

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

JavaScript Interview Question
JavaScript Interview Question

Answer:

<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

Download JavaScript Interview Questions And Answers PDF

Previous QuestionNext Question
What is === operator? How to find radio button selection when a form is submitted?