Note that there are some explanatory texts on larger screens.

plurals
  1. POCheckbox appears unchecked, although it is checked
    primarykey
    data
    text
    <p>I am quite new to jQuery, so my apologizes if there's something obvious I missed but... I just want to have a part of my form to be hidden when a user clicks a checkbox.</p> <p>So, I wrote this small jQuery script:</p> <pre><code>$("#belonging_entire_world").toggle(function() { $("#access_for_friends, #access_for_groups").fadeOut(); }, function(){ $("#access_for_friends, #access_for_groups").fadeIn(); }); </code></pre> <p>When I click the checkbox tagged with the id "belonging_entire_world", it DOES hide the part of the form I want (the part represented by #access_for_friends &amp; #access_for_groups) and if I click again, it shows this part again BUT the checkbox "belonging_entire_world" that I checked always remains visually unchecked...</p> <p>If I open firebug after the script has run, I see that my checkbox does have the checked=checked attribute ... still, it looks unchecked in the browser (in all browsers!)...</p> <p>I tried to add, in the first function of the toggle function the following:</p> <pre><code>$("#belonging_entire_world").attr('checked', true); </code></pre> <p>but still ... it remains as if it was unchecked...</p> <p>This is driving me crazy, I don't see another option that remove the jQuery code, I really don't get it ... I put below part of the view:</p> <pre><code>&lt;div id="Belonging-Access-Control"&gt; &lt;h2&gt; Who will be able to see &amp; access this? &lt;/h2&gt; &lt;div class="field" id="entire_world"&gt; &lt;%= f.check_box(:entire_world) %&gt; &lt;%= f.label(:entire_world, "The entire world!") %&gt; &lt;/div&gt; &lt;div class="field" id="access_for_friends"&gt; &lt;%= f.check_box(:access_for_friends) %&gt; &lt;%= f.label(:access_for_friends, "My friends") %&gt; &lt;/div&gt; </code></pre> <p>and the HTML of the page, after I checked the checkbox (firebug output):</p> <pre><code>&lt;div id="Belonging-Access-Control"&gt; &lt;h2&gt; Who will be able to see &amp;amp; access this? &lt;/h2&gt; &lt;div id="entire_world" class="field"&gt; &lt;input type="hidden" value="0" name="belonging[entire_world]"&gt; &lt;input id="belonging_entire_world" type="checkbox" value="1" name="belonging[entire_world]" checked="checked"&gt; &lt;label for="belonging_entire_world"&gt;The entire world!&lt;/label&gt; &lt;/div&gt; &lt;div id="access_for_friends" class="field" style="display: none;"&gt; &lt;input type="hidden" value="0" name="belonging[access_for_friends]"&gt; &lt;input id="belonging_access_for_friends" type="checkbox" value="1" name="belonging[access_for_friends]"&gt; &lt;label for="belonging_access_for_friends"&gt;My friends&lt;/label&gt; &lt;/div&gt; </code></pre>
    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