Looping through radio button group - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Button

Description

Looping through radio button group

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function loop() {//from   w ww .  j  a v  a 2  s  .  c o m
    var radios = document.getElementsByName("my");
    for (i = 0; i < radios.length; i++) {
        console.log('looping radio ' + i);
    }
};

      </script> 
   </head> 
   <body> 
      <input type="radio" name="my">
      radio1 
      <input type="radio" name="my">
      radio2 
      <input type="button" value="Loop" onclick="loop()">  
   </body>
</html>

Related Tutorials