If any body clicks on radio button list.then we have to show focus in text box near to thatradiobut

Posted by Sun.V under ASP.NET on 9/6/2012 | Points: 10 | Views : 1315 | Status : [Member] | Replies : 3
In my project master page is there. in content page we are having radio button list which is having two elements.
if client click any one of the button we have to show the focus of textbox near by that




Responses

Posted by: Maheshvishnu on: 9/6/2012 [Member] Starter | Points: 25

Up
0
Down
If(radiobutton.selecteditems)
{
textbox.focus();
}

mahesh

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

Posted by: Vasanthmvp on: 9/6/2012 [Member] Starter | Points: 25

Up
0
Down
Hi, here is a simple example:

.aspx page:
<asp:RadioButton ID="radio" runat="server" AutoPostBack="true" Text="Male" OnCheckedChanged="Method" /> <br />
Text: <asp:TextBox ID="txtage" runat="server" />

.aspx.cs:

protected void Method(object sender, EventArgs e)
{
if (radio.Checked)
{
txtage.Focus();
}
}

Regards,

Awesome Coding !! :)

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

Posted by: Ranjeet_8 on: 9/6/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this,

<script type="text/javascript">
function getCheckedRadio() {
var radioButtons = document.getElementsByName('<%=RadioButtonList1.ClientID%>');
if (radioButtons[1].checked) {
document.getElementById('<%= TextBox1.ClientID %>').focus();
}
else {
document.getElementById('<%= TextBox2.ClientID %>').focus();
}
}
</script>

 

<asp:RadioButtonList ID="RadioButtonList1" runat="server" onClick="javascript:return getCheckedRadio();">
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:RadioButtonList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>


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

Login to post response