Jquery checks whether RadioButtonList and RadioButton have selected items.

Source: Internet
Author: User

Copy codeThe Code is as follows:
<Pre class = "html" name = "code"> <% -- Body code -- %>
<Div>
<Asp: RadioButtonList ID = "RadioButtonList1" runat = "server">
<Asp: ListItem Value = "A"> a </asp: ListItem>
<Asp: ListItem Value = "B"> B </asp: ListItem>
</Asp: RadioButtonList>

<Asp: RadioButton ID = "RadioButton1" GroupName = "RBtn" Text = "male" runat = "server" Checked = "true"/>
<Asp: RadioButton ID = "RadioButton2" GroupName = "RBtn" Text = "female" runat = "server"/>

<Asp: Button ID = "Button1" runat = "server" Text = "Button" OnClientClick = "button?clientclick ()"> </asp: Button>
</Div> </pre>

Copy codeThe Code is as follows:
<Pre class = "csharp" name = "code"> <% -- Head code -- %>
<Script language = "javascript" type = "text/javascript" src = "js/jquery-1.9.1.js"> </script>
<Script language = "javascript" type = "text/javascript">

Function Button1_ClientClick ()
{
Alert ($ ("input [name = 'radiobuttonlist1 ']: checked "). val (); // If none are selected, "undefined" is displayed. If any is selected, the corresponding Value is displayed.
If (document. getElementById ("RadioButton1"). checked = true) // if RadioButton1 is selected
{
Alert ($ ("# RadioButton1: checked"). val (); // The RadioButton1 prompt is displayed.
Alert ($ ("# RadioButton2: checked"). val (); // The undefined
Alert ($ ("# RadioButton1: checked"). val () = "RadioButton1"); // true is displayed
}
Return false; // you do not need to upload the data to the background.
}
</Script>
</Pre>

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.