This source code is using the javascript to display the textbox when a radiobutton is clicked. This applies when a user clicks the other specify radio button and the javascript is called to display the textbox. Then, the textbox will be validated if empty.
//Javascript
function InterfaceControl1(id)
{
var radioQ1 = document.getElementsByName(id);
for (var ii = 0; ii < (radioQ1ii++)
{
if (radioQ1[ii].checked){
if (radioQ1[ii].value == “O”){
document.getElementById(“txtQ1”).style.display = ‘inline’; //to show
}
else
{
document.getElementById(“txtQ1”).style.display = ‘none’; //to hide
}
}
}
}
The design code is as below:
<asp:RadioButtonList ID=”rbtnQ1″ runat=”server” RepeatColumns=”2″ RepeatDirection=”Horizontal” CssClass=”chkBoxList” OnClick=”javascript:InterfaceControl1(‘rbtnQ1’);”>
<asp:ListItem Text=”SteelSeries” Value=”SteelSeries”></asp:ListItem>
<asp:ListItem Text=”Razer” Value=”Razer”></asp:ListItem>
<asp:ListItem Text=”Logitech” Value=”Logitech”></asp:ListItem>
<asp:ListItem Text=”Microsoft” Value=”Microsoft”></asp:ListItem>
<asp:ListItem Text=”Others (Please specify)” Value=”O”></asp:ListItem>
</asp:RadioButtonList>
<asp:TextBox ID=”txtQ1″ runat=”server” style=”display:none;” MaxLength=”50″ ValidationGroup=”vdgSubmit”></asp:TextBox>
<asp:RequiredFieldValidator ID=”rfvQ1″ runat=”server” ControlToValidate=”txtQ1″ ErrorMessage=”Please fill in” ForeColor=”Red” ></asp:RequiredFieldValidator>
<br /><br />