Js obtains the data of the single-choice button.

Source: Internet
Author: User

Maybe this is a very simple problem, but I ignored the single-choice button when learning the program. This leads to a gap in his data transfer method. The following table describes how to obtain the data of the age selection form. The test is successful only in IE. First test the effect of this program.
Copy codeThe Code is as follows:
<Form method = "post" name = "form1">
<Label> <input type = "radio" name = "radio" value = "1-10"> 1-10 </label>
<Label> <input type = "radio" name = "radio" value = "11"> 11 </label>
<Label> <input type = "radio" name = "radio" value = "12-120"> 12-120 </label>
<Input type = "button" onclick = "OK ()" value = "test select value">
</Form>

The following is how js obtains data:
Copy codeThe Code is as follows:
<Script language = "javascript" type = "text/javascript">
<! --
Function OK ()
{
Var temp = document. getElementsByName ("radio ");
For (I = 0; I <temp. length; I ++ ){
// Traverse Radio
If (temp [I]. checked)
{Alert ("You selected" + temp [I]. value );
// Obtain the Radio Value
Document. form2.textfield. value = "you have selected" + temp [I]. value;
// Pass it to another form
}
}
}
-->
</Script>

You also want to pass data to another form.
Copy codeThe Code is as follows: <form method = "post" name = "form2">
<Input type = "text" name = "textfield">
</Form>
References
Js: http://www.blueidea.com/tech/web/2006/3567_8.asp
Form: http://www.netvtm.com/w3s/html/html-forms.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.