.NET Framework Developer Center >
.NET Development Forums
>
JScript for the .NET Framework
>
Radio buton list using java script Logic
Radio buton list using java script Logic
Hi
I need this logic could any one please help.
I have two radio button list Each Radio button list having two options
1.) YES
2.) NO
I need the logic in this way. If i click on first Radio button as a option YES then Second Radio Button List automatically selected the NO option.
Otherwise if i click YES option of the second radio button list No Option should select automatically on the First Radio Button List.
Any body please help it should be need in Javascript Function.
Regards
Sujayakumar.Ravipati
Happy Sharepointing Sujayakumar.Ravipati MSBU-IAS WIPRO
All Replies
- Hi kumar,
Here is the code for javascript and ASPX page, dont forget to see the code for codebehind file
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <script language="javascript" type="text/javascript"> function swapFunction(obj, source) { try { // if it is first list if (source == "firstList") { if (obj.value == "1") { // make second list selected value 0 document.getElementById("SecondList_1").checked = true; } else { // make second list selected value 1 document.getElementById("SecondList_0").checked = true; } } else // if source is second list { if (obj.value == "1") { // make first list selected value 0 document.getElementById("FirstList_1").checked = true; } else { // make first list selected value 1 document.getElementById("FirstList_0").checked = true; } } } catch(e) { alert(e.message); } } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:RadioButtonList ID="FirstList" runat="server"> <asp:ListItem Value="1">Yes</asp:ListItem> <asp:ListItem Value="0">No</asp:ListItem> </asp:RadioButtonList> <br /> <asp:RadioButtonList ID="SecondList" runat="server"> <asp:ListItem Value="1">Yes</asp:ListItem> <asp:ListItem Value="0">No</asp:ListItem> </asp:RadioButtonList> </div> </form> </body> </html>
Code Behind C# code
using System; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { foreach (ListItem li in FirstList.Items) { li.Attributes.Add("onclick", "swapFunction(this, 'firstList')"); } foreach (ListItem li2 in SecondList.Items) { li2.Attributes.Add("onclick", "swapFunction(this, 'secondList')"); } } }
Please mark it as an Answer if it works for you.
Microsoft.Ninja


