JS determines whether the Radio button is selected and the value information is displayed.

Source: Internet
Author: User

Problems solved in today's project: JS checks whether the Radio radio button is selected and displays the value information. The Radio value is not always obtained at first, and later finds some logic problems, I would like to share this code to take notes and share it with my colleagues who have encountered such problems:


[Javascript]
<Script type = "text/javascript">

// Judge the five Radio functions that are selected
Function judgeRadioClicked ()
{
// Obtain the name set of the single-choice button
Var radios = document. getElementsByName ("radio_tj ");

// Traverse the name set based on the length of the name set
For (var I = 0; I <radios. length; I ++)
{
// Determine which radio button is selected
If (radios [I]. checked)
{
// The value of the selected radio button is displayed.
Alert (radios [I]. value );
}
}
 
}

</Script>

Note: // obtain the name set of the single-choice button // var radios = document. getElementsByName ("radio_tj"); "radio_tj" indicates the name attribute of the single-choice button set.


Over !!!

 

From SongYanJun2011

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.