If a set of radio buttons are used in the form (Form name form1) on the web page, the name is button1.
To obtain the value of the selected button from JS, follow these steps:
<Script language = JavaScript>
Function getradiovalue ()
{
VaR STR;
For (I = 0; I <document. form1.button1. length; I ++)
{
If (document. form1.button1 [I]. Checked)
STR = Document. form1.button1 [I]. value;
}
}
</SCRIPT>
Here, the radio name button1 is equivalent to an array name.
Related examples:
<Input type = "radio" name = "radiobuttn" value = "A" Checked> one <br> <input type = "radio" name = "radiobuttn" value = "B"> two <br> <input type = "radio" name = "radiobuttn" value = "C"> three <br> <input type = "radio" name = "radiobuttn" Value = "D"> four all four radio button objects have the same name: radiobuttn,
HTML and JavaScript know that they are objects in the same number of groups. Second,
The value of each option is the alias of the option, not the text displayed (for example, "one" or "two ).
To obtain the value of the selected option, you must first know which option is selected, and then in the alert statement,
Use the value of the selected option to correctly reference the value of the current option. That is to say,
If the first option is selected, you should use radiobuttn [0]. value. If the second option is selected,
You should take radiobuttn [1]. value, and so on.
In JavaScript, some types of fields have the selectedindex attribute,
The value of the selected array. However, the single-choice button is not so lucky,
Similarly, the check box does not escape bad luck. To get the value of the selected radio button,
You must search for the "checked" attribute in the radiobuttn array element.
Below is the buttonCode:
VaR Doc = Document. Forms [0];
For (I = 0; I <Doc. radiobuttn. length; I ++)
{
If (Doc. radiobuttn [I]. Checked)
{
Alert (Doc. radiobuttn [I]. value );
Break;
}
}
RelatedArticleConnection of: http://www-900.ibm.com/developerWorks/cn/lotus/lo-jsobj/index.shtml