Http://blog.sina.com.cn/s/blog_50a1e17401017pik.html
Advance Knowledge Preparation:
In an HTML document, each element can set the ID and name attribute.
Where the id attribute is a unique attribute and cannot be duplicated, an ID value can only correspond to one element;
The Name property can be repeated, and a name value can correspond to a set of elements.
Therefore, only one selected HTML element is returned when using the document.getelementbyidx_x (ID);
When you use Document.getelementsbyname (NAME), you return an array of multiple HTML elements
(an array is returned even if there is only one element in the HTML page that meets the requirements.)
Document.getelementsbyname (NAME) is used to select a set of CheckBox or radio in form forms
Method 1:
<script type = "Text/javascript" >
function Change ()
{
var radio =document.getelementsbyname ("Form1");
var radio =document.getelementbyidx_x ("Form1");
You can't get all the radio values with Byid, but each return is 1.
Varradiolength = Radio.length;
for (var i =0;i < radiolength;i++)
{
if (radio[i].checked)
{
Varradiovalue = Radio[i].value;
alert (Radiovalue);
}
}
}
</script>
<body>
<input type = "Radio" id = "Form1" name = "Form1" value = "1" onchange = "Change ();" > Option 1
<input type = "Radio" id = "Form1" name = "Form1" value = "2" onchange = "Change ();" > Option 2
</body>
Method 2:
<script type = "Text/javascript"
function change ()
{
varnew=document.getelementsbyname ("Form1");
varstrNew;
for (vari=0;i<new.length;i++)
{
if ( New.item (i). Checked)
{
Strnew=new.item (i). getattribute ("value");
alert (strnew); Item () Method: Returns the current item in the collection
Break
}
Else
{
Continue
}
}
}
</script>
<body>
<input type = "Radio" id = "Form1" name = "Form1" value = "1" onchange = "Change ();" > Option 1
<input type = "Radio" id = "Form1" name = "Form1" value = "2" onchange = "Change ();" > Option 2
</body>