JS how to get the value of the selected radio radio button:
Radio radio Button is one of the most common form elements, often need to get the value of the selected button, the following is an example of how to use JavaScript to implement this function, code examples are as follows:
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.softwhy.com/" /><title>Ant Tribe</title><Scripttype= "Text/javascript">window.onload=function(){ varObox=document.getElementById ("Box"); Radios=Obox.getelementsbytagname ("input"); varBT=document.getElementById ("BT"); Bt.onclick=function() { for(varI=0; I<Radios.length;i++) { if(radios[i].checked==true) {alert (radios[i].value); } } }}</Script></Head><Body><DivID= "box"> <inputtype= "Radio"name= "RA"value= "1"/> <inputtype= "Radio"name= "RA"value= "2"/> <inputtype= "Radio"name= "RA"value= "3"/> <inputtype= "Radio"name= "RA"value= "4"/> <inputtype= "Radio"name= "RA"value= "5"/></Div><inputtype= "button"ID= "BT"value= "Click to view Results" /></Body></HTML>
The above code when clicking on the button can pop up the selected radio button Value property value, the code is very simple the following is a brief introduction to the implementation process.
I. Principle of implementation:
Use the getElementsByTagName () function to get the INPUT element object under the Div, which is the radio button in this code, and then iterate through each button with a for loop, and determine if the value of the current radio button's Checked property is true. If Tue is selected, then the Value property values are popped, which is generally true.
two. Related reading:
1.window.onload can be found in the window.onload usage section.
the 2.getElementById () function can be found in the document.getElementById () method section of JavaScript .
the 3.getElementsByTagName () function can be found in the document.getElementsByTagName () section of JavaScript .
4.onclick events can be found in the OnClick events section of JavaScript .
5.checked properties can be found in the Radio.checked Properties section of JavaScript .
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=9693
For more information, refer to: http://www.softwhy.com/javascript/
JS how to get the value of the selected radio radio button