Subscribe to Subscribers
Talk to Webmaster Tony John

Online Members

More...

Forums » .NET » JavaScript »

Change the asp radio button based on the drop down list item


Posted Date: 02 Jul 2012      Posted By:: rkb     Member Level: Silver    Member Rank: 967     Points: 3   Responses: 5



How to change the asp radio button list value based on the drop down list selected item chnages any sample are code?

for eg:

aspradiobutton yes no

if the drop down list values
apple
grapes
orange

if apple is selected the radio button list value is to be change as yes

if grape are orange is selected radio button list value is to be change as no

any sample?




Responses

#678490    Author: Ravindran        Member Level: Diamond      Member Rank: 3     Date: 02/Jul/2012   Rating: 2 out of 52 out of 5     Points: 4

Try like below code as per your requirement


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Javascript Radiobutton list selection</title>
<script type="text/javascript">
function chk()
{
var radval = document.getElementById('rad1');
var radlist = radval.getElementsByTagName('input');
if(document.getElementById("DropDownList1").value=="apple")
{
radlist.item(0).checked=true;
}
else
{
radlist.item(1).checked=true;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList ID="rad1" runat="server">
<asp:ListItem Value="1">Yes</asp:ListItem>
<asp:ListItem Value="2">No</asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:DropDownList ID="DropDownList1" runat="server" onchange='chk();'>
<asp:ListItem>apple</asp:ListItem>
<asp:ListItem>grapes</asp:ListItem>
<asp:ListItem>orange</asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>


Regards
N.Ravindran
Your Hard work never fails



 
#678528    Author: rkb      Member Level: Silver      Member Rank: 967     Date: 02/Jul/2012   Rating: 2 out of 52 out of 5     Points: 1

hi,

The above example doesn't work any solution?



 
#678651    Author: Ravindran        Member Level: Diamond      Member Rank: 3     Date: 03/Jul/2012   Rating: 2 out of 52 out of 5     Points: 1

Hi,

The above code works fine here just copy paste my code and test it

Regards
N.Ravindran
Your Hard work never fails






 
#678687    Author: rkb      Member Level: Silver      Member Rank: 967     Date: 03/Jul/2012   Rating: 2 out of 52 out of 5     Points: 1

function chk()
{ alert('1');
var radval = document.getElementById('<%=rad1.ClientID%>');
var radlist = radval.getElementsByTagName('input');
if(document.getElementById('<%=DropDownList1.ClientID%>').value=="apple")
{alert('2');

radlist.item(0).checked=true;

}
else
{alert('3');
radlist.item(1).checked=true;
}
}

The above code gets the alert but not changing the selected value in UI for the radio button list any solution?



 
#679254    Author: Ultimaterengan        Member Level: Gold      Member Rank: 9     Date: 06/Jul/2012   Rating: 2 out of 52 out of 5     Points: 2


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;

public partial class _Default : System.Web.UI.Page
{


protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedItem.Text == "A")
{
Radio1.Checked = true;
Radio2.Checked = true;
Radio3.Checked = true;

}
else
{
Radio1.Checked = false;
Radio2.Checked = false;
Radio3.Checked = false;
}
}
}
<%@ 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>

</head>
<body>
<form id="form1" runat="server">
<input id="Radio1" runat="server" name="a" type="radio" />
<input id="Radio2" runat="server" name="a" type="radio" />
<input id="Radio3" runat="server" name="a" type="radio" />
<asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>a</asp:ListItem>
<asp:ListItem>b</asp:ListItem>
</asp:DropDownList>
</form>
</body>
</html>





Thanks & Regards
G.Renganathan
Nothing is mine ,Everything is yours!!!


http://renganathan1984.blogspot.com/



 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Google Translate Customization
Previous : How to get image ids using java script
Return to Discussion Forum
Post New Message
Category:

Related Messages
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2012 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.