radio button

Posted by Abhi_patil under ASP.NET on 5/30/2009 | Views : 2429 | Status : [Member] | Replies : 2
i have used asp control radio button group.
also there are textboxes on my form i want to change textboxes on radio buton click.

ex 3 text boxes text1,text2,text3 and 3 radio buttons.

when click radio button 1 then make visible only text1,for radio button 2 then make visible only text3,and for radio button 3 then make visible only text3.

using java script...but radio buttons are asp controls..




Responses

Posted by: Syedshakeer on: 5/31/2009 [Member] Starter

Up
0
Down
Hi Abhi_patil
First set AutoPostBak ="True" to RadioButtonList1and make all texbox Visible=False
Double click your RadioButtonList and use Below Code:

[code]
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{

if (RadioButtonList1.Items[0].Selected == true)
{
textbox1.Visible="True";
textbox2.Visible="False";
textbox3.Visible="False";

}
if (RadioButtonList1.Items[1].Selected == true)
{
textbox1.Visible="False";
textbox2.Visible="True";
textbox3.Visible="False";

}

if (RadioButtonList1.Items[2].Selected == true)
{
textbox1.Visible="False";
textbox2.Visible="False";
textbox3.Visible="True";

}

}
}
[/code]

Syed Shakeer Hussain

Abhi_patil, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vikranth4u on: 6/1/2009 [Member] Starter

Up
0
Down
Dear Abhi,

Plz find the solution .I think it's helpful for u

<head runat="server">
<title>Untitled Page</title>

<script language="javascript" type="text/javascript">
function abc(rbl)
{

var e = document.forms[0].elements[rbl];
var id;
for (var j=0; j < e.length; j++)
{
if (e[j].checked)
{
id =e[j].value;
}
}
document.getElementById('div1').style.display='inline';
var elements=document.getElementsByTagName('INPUT');
for( k=0; k<elements.length;k++)
{
if(elements[k].type=='text')
{
if(elements[k].id.lastIndexOf(id) > 0)
elements[k].style .display='inline'
else
elements[k].style.display='none'
}
}

}


</script>

</head>
<body>
<form id="form1" runat="server">

<asp:RadioButtonList ID="RadioButtonList1" runat="server" onChange="abc(this.id)">
<asp:ListItem Value="1">a1</asp:ListItem>
<asp:ListItem Value="2">a2</asp:ListItem>
<asp:ListItem Value="3">a3</asp:ListItem>
</asp:RadioButtonList>
<div id="div1" style="display: none">
<input type="text" id="text1" runat="server" />
<input type="text" id="text2" runat="server" />
<input type="text" id="text3" runat="server" />
</div>

</form>
</body>
</html>


Regards
Vikranth Reddy Mula


Abhi_patil, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response