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

Bharathi Cherukuri
Posted by Bharathi Cherukuri under JavaScript category on | Points: 40 | Views : 1284
Below is an example for finding the selected radio button immediately using '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

Comments or Responses

Login to post response