Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you've already realised that RadioButtonList controls are rendered as a <code>&lt;table&gt;</code> with each radio button as an <code>&lt;input&gt;</code> within that table. Therefore getting a handle on RadioButtonList1 and trying to access it as an array using <code>MyRadio[j]</code> isn't going to work.</p> <p>I think the following line:</p> <pre><code>var options = document.getElementsByTagName("input") </code></pre> <p>Should instead read:</p> <pre><code>var options = MyRadio.getElementsByTagName("input") </code></pre> <p>That will give you just a collection of the input tags within that RadioButtonList control rather than all those on the page. Once you have that options collection, you shouldn't need to refer to the RadioButtonList control again.</p> <p>I understand that this is drastically simplified over what you have, but here's an example for you:</p> <pre><code>&lt;form runat="server"&gt; &lt;asp:RadioButtonList runat="server" id="RadioButtonList1"&gt; &lt;asp:ListItem&gt;Yes&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;No&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;N/A&lt;/asp:ListItem&gt; &lt;/asp:RadioButtonList&gt; &lt;input type="button" onclick="fcnUpdateMain()" value="Click" /&gt; &lt;script type="text/javascript"&gt; function fcnUpdateMain() { var MyRadio = document.getElementById("&lt;%=RadioButtonList1.ClientID%&gt;") var options = MyRadio.getElementsByTagName("input") var somethingChecked = false; for( x = 0; x &lt; options.length; ++x ) { if (options[x].checked) { somethingChecked = true; } } if (!somethingChecked) { alert("You must select an answer for all questions.") return false; } } &lt;/script&gt; &lt;/form&gt; </code></pre>
 

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