Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>EDITED: Changed some code, damn old jquery.</p> <p>First off, your radios have no values. That's going to be a fly in your ointment, since they're both the same.</p> <p>For your HTML, I would do:</p> <pre><code>&lt;li class="group" id="group1"&gt; &lt;div class="yes"&gt;&lt;input type="radio" name="group1" value="yes"&gt;&lt;/div&gt; &lt;div class="no"&gt;&lt;input type="radio" name="group1" value="no"&gt;&lt;/div&gt; Group 1 &lt;ul&gt; &lt;li&gt; &lt;div class="yes"&gt;&lt;input type="radio" name="Item1" value="yes"&gt;&lt;/div&gt; &lt;div class="no"&gt;&lt;input type="radio" name="Item1" value="no"&gt;&lt;/div&gt; Item 1 &lt;/li&gt; &lt;li style="padding-left:25px"&gt; &lt;div class="yes"&gt;&lt;input type="radio" name="Item2" value="yes"&gt;&lt;/div&gt; &lt;div class="no"&gt;&lt;input type="radio" name="Item2" value="no"&gt;&lt;/div&gt; Item 2 &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; </code></pre> <p>The extra serves the dual functions of delimiting the subgroups in a logical way, and providing a nice hook. Instead of setting the padding as a style, do li ul li{ padding-left: 25px;}</p> <p>Then, you can do</p> <pre><code> $(document).ready(function(){ $(".group&gt;div&gt;input").change(function(){ val = $(".group&gt;div&gt;input:checked").val(); var inputs = $(this).parents("li").find("ul li div input[@value="+val+"]"); inputs.each(function(){$(this).attr("checked","checked")}); }); }); </code></pre> <p>This will trigger the inside function on a change in one of the group 1 inputs.</p>
 

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