Reputation: 610
i have radio button in my pages, what i want to do is pretty easy, once radio1 is checked, then unchecked radio2, else radio1 is unchecked
<asp:RadioButton id="rdlMember" runat="server" Text="Member"
onClick ="mtdMode(this.id);" />
<asp:RadioButton id="rdlNonMember" runat="server" Text="Non Member"
onClick ="mtdMode(this.id);" />
i have created a javascript function in my pages
function mtdMode(ClientID) {
var id = ClientID.split("_").pop();
var rdlMember= document.getElementById("rdlMember");
var rdlNonMember= document.getElementById("rdlNonMember");
if (id == "rdlMember") {
rdlNonMember.checked = false;
} else if (id == "rdlNonMember") {
rdlMember.checked = false;
}
};
this is not working, however i checked my id from ie developer tool, this id format is render as below and if i change my code as below then work, however this is not my objective, is that any others way to get radiobutton id?
document.getElementById
("ctl00_m_g_2d869ad7_689c_4d9b_88b8_774ae48d99ab_ctl00_rdlNonMember").checked = false;
document.getElementById
("ctl00_m_g_2d869ad7_689c_4d9b_88b8_774ae48d99ab_ctl00_rdlMember").checked = false;
Upvotes: 0
Views: 47
Reputation: 31903
Radio buttons do that by default when they have the same name. You need to use GroupName
in the <asp:RadioButton />
tags.
See http://www.w3schools.com/aspnet/control_radiobutton.asp
The plain HTML example is at http://www.w3schools.com/html/tryit.asp?filename=tryhtml_radio
Upvotes: 1