How to use JavaScript to obtain the radio selected value

Source: Internet
Author: User
I was working on Web six years ago. Three years ago, I was bored with web development. Recently, I picked up Web development again and forgot how to use radio.
Document. getelementbyid ("radioname"). value does not work, So Google knows that this is not the case.

The following is an example:

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "">
<HTML xmlns = "">
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> untitled document </title>
<Script language = "JavaScript">
Function getradioboxvalue (radioname)
VaR OBJ = Document. getelementsbyname (radioname );
For (I = 0; I <obj. length; I ++ ){
If (OBJ [I]. Checked ){
Return OBJ [I]. value;
Return "undefined ";

Function ABC (){
VaR A = getradioboxvalue ("radiobutton ");
Alert ();

<Form ID = "form1" name = "form1" method = "Post" Action = "">
<Input type = "radio" name = "radiobutton" value = "AA"/>
AA </label>
<Input type = "radio" name = "radiobutton" value = "BBB" checked/>
Bbb </label>
<Input type = "radio" name = "radiobutton" value = "CCC"/>
CCC </label>

<Input type = "Submit" name = "Submit" value = "Submit" onclick = "ABC ()"/>


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: 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.