JQuery checks whether radio is selected and obtains the selected value.

Source: Internet
Author: User

JQuery checks whether radio is selected and obtains the selected value.

A JQuery method is used to determine whether radio is selected and obtain the selected value. There is nothing special to mention. You can use it directly.

 

 

The Code is as follows:  

Other radio operations will be added later. Run the Code directly.

<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> JQuery radio </title>
<Script type = "text/javascript" language = "javascript" src = "http://www.aimks.com/wp-includes/js/jquery/jquery.js"> </script>
<Script type = "text/javascript" language = "javascript">
/* ------ Determine whether radio is selected and obtain the selected value --------*/
$ (Function (){
$ ("# BtnSubmit"). click (function (){
Var val = $ ('input: radio [name = "sex"]: checked'). val ();
If (val = null ){
Alert ("Nothing selected! ");
Return false;
}
Else {
Alert (val );
}
Var list = $ ('input: radio [name = "list"]: checked'). val ();
If (list = null ){
Alert ("Please select one! ");
Return false;
}
Else {
Alert (list );
}
});
});
</Script>
</Head>

<Body>
<Form id = "form1">
<Input type = "radio" name = "sex" value = "male"/> male
<Input type = "radio" name = "sex" value = "female"/> female
<Br/>
<Input type = "radio" name = "list" value = "very satisfied"/> very satisfied
<Input type = "radio" name = "list" value = "satisfied"/> satisfied
<Input type = "radio" name = "list" value = "not satisfied"/> not satisfied
<Input type = "radio" name = "list" value = "very poor"/> very poor
<Br/>
<Input type = "submit" value = "submit" id = "btnSubmit"/>
</Form>
</Body>
</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.