Note that there are some explanatory texts on larger screens.

plurals
  1. POHide/Show Based on Radio Button Click
    primarykey
    data
    text
    <p>I've been searching for a few hours now and haven't been able to get an aspect of my code working.</p> <p>I have two radio buttons for a div, and I want it so if I select Yes, it shows one slider, if I selected No, it shows another.</p> <p>Below is the .html:</p> <pre><code>&lt;fieldset data-role="controlgroup"&gt; &lt;legend&gt; &lt;h&gt;Do you like pie?&lt;/h&gt; &lt;/legend&gt; &lt;input type="radio" name="do-you-like-pie" id="do-you-like-pie-yes" value="do-you-like-pie-yes" checked="checked" /&gt; &lt;label for="do-you-like-pie-yes"&gt;Yes&lt;/label&gt; &lt;input type="radio" name="do-you-like-pie" id="do-you-like-pie-no" value="do-you-like-pie-no" /&gt; &lt;label for="do-you-like-pie-no"&gt;No&lt;/label&gt; &lt;/fieldset&gt; &lt;!-- first slider --&gt; &lt;div data-role="fieldcontain" class="show-hide-like-pie-no"&gt; &lt;label for="like-pie-yes-slider"&gt; &lt;h&gt;How much?&lt;/h&gt; &lt;/label&gt; &lt;input type="range" name="like-pie-yes-slider" id="like-pie-yes-slider" value="25" min="0" max="100" data-highlight="true" /&gt; &lt;/div&gt; &lt;!-- 2nd slider --&gt; &lt;div data-role="fieldcontain" class="show-hide-like-pie-yes"&gt; &lt;label for="like-pie-no-slider"&gt; &lt;h&gt;How litle?&lt;/h&gt; &lt;/label&gt; &lt;input type="range" name="like-pie-no-slider" id="like-pie-no-slider" value="100" min="0" max="200" data-highlight="true" /&gt; &lt;/div&gt; </code></pre> <p>Below is the .js:</p> <pre><code>function getAuto() { if ($('#do-you-like-pie-yes').is(':checked')) { return true; } else { return false; } } //$('do-you-like-pie').on('click',function () { // if ($('#do-you-like-pie-yes').is(':checked')) { if (getAuto() == "true") { $(".show-hide-like-pie-yes").show(); $(".show-hide-like-pie-no").hide(); } else { $(".show-hide-like-pie-yes").hide(); $(".show-hide-like-pie-no").show(); } //}); </code></pre> <p>Any help would be greatly appreciated!</p> <p>Here is the fiddle link: <a href="http://jsfiddle.net/DjT5X/" rel="nofollow">http://jsfiddle.net/DjT5X/</a></p> <p>Thanks!</p> <p>Kind Regards,</p> <p>Gary</p> <p>edit: the trouble with other solutions is that they don't use an "if"</p>
    singulars
    1. This table or related slice is empty.
    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