jquery - Toggle DIV when Radio Buttons are checked -


i trying make div toggle visible , not visible when group of radio buttons yes or no.

for example have a list of stores in div want list of stores visible when radio button checked yes.

edit script view

<div id="script_form_wrapper">     <%= form_for(:script, :url => {:action => 'update', :id =>@script.id}) |f| %>         <div id="script_form_visibility">             <div class="issue_section_header" align="center">visibility</div>             <div class="line-break"></div>             <div class="standardtext"><span class="boldtext">all stores:</span>                  <%=f.radio_button(:all_stores, true)%> yes                  <%=f.radio_button(:all_stores, false)%> no             </div>             <br/>             <div id="script_stores">                 <div class="issue_section_header" align="center">stores</div>                 <div class="line-break"></div>                 <div class="standardtext">                     <%@stores.each |store|%>                         <%= check_box_tag 'script[store_ids][]', store.id, @script.store_ids.include?(store.id), :id => dom_id(store) %>                         <%= label_tag dom_id(store), store.name, :class => "check_box_label" %><br/>                     <%end%>                 </div>             </div>         </div>         <div id="script_form">             <div class="boldtext"><%= f.label :name %></div>             <div><%=f.text_field :name, :size => '94', :maxlength => '70'%></div>             <div>                 <table width="100%" cellspacing="0">                     <tr>                         <td class="boldtext"><%= f.label :category_id, "category" %></td>                         <td class="boldtext" align="right">show id required field</td>                     </tr>                     <tr>                         <td class="standardtext"><%=f.select(:category_id, @categories.collect {|c| [c.name, c.id]}, :selected => session[:admin_category])%></td>                         <td class="standardtext" align="right"><%=f.radio_button(:require_id, true)%> yes <%=f.radio_button(:require_id, false)%> no</td>                     </tr>                 </table>             </div>             <div class="boldtext"><%= f.label :task %></div>             <div><%= f.text_area(:task, :size => "68x20") %></div>             <div class="boldtext"><%= f.label :expected_results, "expected results" %></div>             <div><%= f.text_area(:expected_results, :size => "68x20") %></div>             <div align="center"><%= f.submit "update script" %></div>         </div>     <% end %> </div> 

sad attempt of javascript

<script type="text/javascript">  $(function() {     $("[name=script[all_stores]]").click(function(){             $('#script_stores').hide();             $("#script_all_stores_"+$(this).val()).show('slow');     });  }); </script> 

rendered html source

<div class="standardtext"><span class="boldtext">all stores:</span>                  <input id="script_all_stores_true" name="script[all_stores]" type="radio" value="true" /> yes                  <input checked="checked" id="script_all_stores_false" name="script[all_stores]" type="radio" value="false" /> no             </div> 

solution

<script type="text/javascript">  $(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();                  }     }); });    </script> 

thank you help!!!

  $("[name=script[all_stores]]").change(function(){         $('#script_stores').toggle();              }); 

or

      $("[name=script[all_stores]]").change(function(){          if($(this).is(":checked")){            $('#script_stores').show();             }else {            $('#script_stores').hide();             }        }); 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -