JavaScript determines which radio button is selected when the form is submitted

  • 2020-05-17 04:50:13
  • OfStack

This example demonstrates how JavaScript determines which radio button is selected when a form is submitted. Share with you for your reference. The specific analysis is as follows:

The form submission here USES JavaScript to determine which radio button is selected


<script type="text/javascript">
function findButton() {
var myForm = document.forms.animalForm;
var i;
for(i=0;i<myForm.marsupial.length; i++) {
  if(myForm.marsupial[i].checked) {
   break;
  }
}
alert("You selected \""+myForm.marsupial[i].value+"\".");
}
</script>
<form name="animalForm">
<input type="radio" name="marsupial" value="kangaroo" />ofstack.com
<br />
<input type="radio" name="marsupial" value="Opossum" />Opossum
<br />
<input type="radio" name="marsupial" value="Tasmanian Tiger" />Tasmanian Tiger
<br />
<input type="button" name="GO" value="GO" onclick="findButton()" />
</form>

I hope this article has been helpful to your javascript programming.


Related articles: