SoFunction
Updated on 2025-04-08

Javasipt: Detailed explanation of operation radio tags

1. HTML code:

Copy the codeThe code is as follows:

      <form action="#" name="userOpinionForm" method="post">

<input type="radio"    name="opinionCategory" value="1" checked  /> Most agree
<input type="radio"    name="opinionCategory" value="0" /> Most disagree

      </form>


2. js code:
Method 1:
Copy the codeThe code is as follows:

var opinionCategory = ('opinionCategory');

                 var opinionCategoryValue = 1;
                 for(var i=0;i<;i++){
                        if(opinionCategory[i].checked){
                                      opinionCategoryValue = opinionCategory[i].value;
                        }
                 }


Method 2:
Copy the codeThe code is as follows:

var form = ('userOpinionForm');

                 var num = 0;
                 for(var i=0;i<;i++){
                     if([i].checked){
                         num++;
                     }
                 }