Note that there are some explanatory texts on larger screens.

plurals
  1. POCustomValidator textbox required on radiobuttonlist select
    primarykey
    data
    text
    <p>On my page I have a Radio button list and a textbox.</p> <p>The textbox is hidden by default then appears if the user clicks yes. Once they click yes then the textbox must be filled in before they can proceed.</p> <p>I've put in the following code, however it doesn't seem to work at all and when the button is pressed to go to the next page it continues instead of stopping and asking the user to enter something in the box.</p> <pre><code>function Q12iYes() { document.getElementById('txt12i').style.display = "block" } function Q12iNo() { document.getElementById('txt12i').style.display = "none" } &lt;asp:RadioButtonList ID="rbtn12" runat="server" RepeatDirection="Horizontal"&gt; &lt;asp:ListItem Value="Yes" onclick="Q12iYes()" /&gt; &lt;asp:ListItem Value="No" Selected="True" onclick="Q12iNo()" /&gt; &lt;/asp:RadioButtonList&gt; &lt;br /&gt; 12.i) If &amp;#39;Yes&amp;#39; please provide details&lt;br /&gt; &lt;br /&gt; &lt;asp:TextBox ID="txt12i" runat="server" Height="62px" TextMode="MultiLine" Width="343px"&gt;&lt;/asp:TextBox&gt; &lt;br /&gt; &lt;asp:CustomValidator ID="MyTxtBoxValidator" runat="server" ControlToValidate="txt12i" ValidateEmptyText="true" ErrorMessage="Please enter some values into Textbox" ClientValidationFunction="validateMyBtn" Display="Dynamic"&gt; &lt;/asp:CustomValidator&gt; &lt;script type="text/javascript"&gt; function validateMyBtn(oSrc, args) { var rbtnValue = null; var rbtnList = document.getElementsByName('&lt;%=rbtn12.ClientID %&gt;'); var radio = rbtnList[0].getElementsByTagName("input"); for (var i = 0; i &lt; radio.length; i++) { if (radio[i].checked) rbtnValue = radio[i].value; } if (rbtnValue == "Yes") { args.IsValid = !(args.Value == "") } else { args.IsValid = true; } } &lt;/script&gt; &lt;asp:Button ID="btnContinue" runat="server" OnClick="btnContinue_Click" Text="Continue" /&gt; </code></pre> <p>I have had a look for how to do it, but nothing I have seen has worked either, or helped me understand where I'm going wrong. </p> <p>Can anyone help?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload