Note that there are some explanatory texts on larger screens.

plurals
  1. POToggle DIV when Radio Buttons are checked
    primarykey
    data
    text
    <p>I am trying to make a DIV toggle visible and not visible when a group of radio buttons say yes or no.</p> <p>For example I have a a list of stores in a DIV but I only want that list of stores visible when the radio button is checked as yes.</p> <p><strong>Edit Script View</strong></p> <pre><code>&lt;div id="script_form_wrapper"&gt; &lt;%= form_for(:script, :url =&gt; {:action =&gt; 'update', :id =&gt;@script.id}) do |f| %&gt; &lt;div id="script_form_visibility"&gt; &lt;div class="issue_section_header" align="center"&gt;Visibility&lt;/div&gt; &lt;div class="line-break"&gt;&lt;/div&gt; &lt;div class="standardText"&gt;&lt;span class="boldText"&gt;All Stores:&lt;/span&gt; &lt;%=f.radio_button(:all_stores, true)%&gt; Yes &lt;%=f.radio_button(:all_stores, false)%&gt; No &lt;/div&gt; &lt;br/&gt; &lt;div id="script_stores"&gt; &lt;div class="issue_section_header" align="center"&gt;Stores&lt;/div&gt; &lt;div class="line-break"&gt;&lt;/div&gt; &lt;div class="standardText"&gt; &lt;%@stores.each do |store|%&gt; &lt;%= check_box_tag 'script[store_ids][]', store.id, @script.store_ids.include?(store.id), :id =&gt; dom_id(store) %&gt; &lt;%= label_tag dom_id(store), store.name, :class =&gt; "check_box_label" %&gt;&lt;br/&gt; &lt;%end%&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="script_form"&gt; &lt;div class="boldText"&gt;&lt;%= f.label :name %&gt;&lt;/div&gt; &lt;div&gt;&lt;%=f.text_field :name, :size =&gt; '94', :maxlength =&gt; '70'%&gt;&lt;/div&gt; &lt;div&gt; &lt;table width="100%" cellspacing="0"&gt; &lt;tr&gt; &lt;td class="boldText"&gt;&lt;%= f.label :category_id, "Category" %&gt;&lt;/td&gt; &lt;td class="boldText" align="right"&gt;Show ID Required Field&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="standardText"&gt;&lt;%=f.select(:category_id, @categories.collect {|c| [c.name, c.id]}, :selected =&gt; session[:admin_category])%&gt;&lt;/td&gt; &lt;td class="standardText" align="right"&gt;&lt;%=f.radio_button(:require_id, true)%&gt; Yes &lt;%=f.radio_button(:require_id, false)%&gt; No&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;div class="boldText"&gt;&lt;%= f.label :task %&gt;&lt;/div&gt; &lt;div&gt;&lt;%= f.text_area(:task, :size =&gt; "68x20") %&gt;&lt;/div&gt; &lt;div class="boldText"&gt;&lt;%= f.label :expected_results, "Expected Results" %&gt;&lt;/div&gt; &lt;div&gt;&lt;%= f.text_area(:expected_results, :size =&gt; "68x20") %&gt;&lt;/div&gt; &lt;div align="center"&gt;&lt;%= f.submit "Update Script" %&gt;&lt;/div&gt; &lt;/div&gt; &lt;% end %&gt; &lt;/div&gt; </code></pre> <p><strong>Sad Attempt of Javascript</strong></p> <pre><code>&lt;script type="text/javascript"&gt; $(function() { $("[name=script[all_stores]]").click(function(){ $('#script_stores').hide(); $("#script_all_stores_"+$(this).val()).show('slow'); }); }); &lt;/script&gt; </code></pre> <p><strong>Rendered HTML Source</strong></p> <pre><code>&lt;div class="standardText"&gt;&lt;span class="boldText"&gt;All Stores:&lt;/span&gt; &lt;input id="script_all_stores_true" name="script[all_stores]" type="radio" value="true" /&gt; Yes &lt;input checked="checked" id="script_all_stores_false" name="script[all_stores]" type="radio" value="false" /&gt; No &lt;/div&gt; </code></pre> <p><strong>Solution</strong></p> <pre><code>&lt;script type="text/javascript"&gt; $(function() { if($("#script_all_stores_false").is(":checked")){ $('#script_stores').show(); }else{ $('#script_stores').hide(); } $("input[name='script[all_stores]']").change(function(){ if($("#script_all_stores_false").is(":checked")){ $('#script_stores').show(); }else{ $('#script_stores').hide(); } }); }); &lt;/script&gt; </code></pre> <p>Thank you for you 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.
    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