views:

202

answers:

1

Hey, I have a code segment here:

<div class="label"><%= f.label :course %> <span>(Does this relate to a specific course?)</span></div>
    <%= check_box_tag(:no_course) %>
      <%= label_tag(:no_course, "None") %><br />
    <%= f.collection_select(:course_id, @current_account.courses.find(:all, :order => "name"), :id, :name) %>

How could I make it so that

<%= f.collection_select(:course_id, @current_account.courses.find(:all, :order => "name"), :id, :name) %>

only shows when

<%= check_box_tag(:no_course) %>

Is selected using javascript?

Thanks!

+1  A: 

If you are doing it with jQuery, do this in your document.ready:

if(!$('.no_course:checked').length) {
   $('myElementSelectedByClass').hide();
}

I am assuming here that it is originally shown and you are hiding it when the page loads. The basic premise is to get your checkbox DOM Element (in this case I get by class name) and see if the checked attribute is set. If not then hide it.

Keith Rousseau