On Oct 24, 2011, at 8:53 AM, Sebastian wrote:

> Yes you are right! Yours is looking better!
> 
> But I am not getting it to work!
> 
> I have now the followinfg in my public/javascripts/application.js:
> 
> $("#filters input:checkbox").click(function(){
>   class_to_show =  $(this).attr("id");
>  switch(class_to_show){
>      case 'show1':
>         $(".show1").show();
>         $(".show2").hide();
>      break;
>      case 'show2':
>         $(".show1").hide();
>         $(".show2").show();
>      break;
>      default
>         $(".show1").show();
>         $(".show2").show();
>   }
> 
> });
> 
> My form is looking like that:
> 
> <form id="filters">
> <%= check_box_tag  'show1', 'show' %>
> <%= check_box_tag  'show2', 'show' %>
> <%= check_box_tag  'showall', 'show' %>
> </form>
> 
> And my table where I want to show and hide rows like this:
> 
> <table border=1>
>  <tr class="show1">
>    <td>Hi</td>
>    <td>How</td>
>  </tr>
>  <tr class="show2">
>    <td>Are</td>
>    <td>You</td>
>  </tr>
> </table>
> 
> What I am doing wrong???

Check to be absolutely certain you are using jQuery rather than Prototype. 
While most of this code will work fine with either, the basic accessor 
(shortcut for findElementById) in Prototype is $('theId'), while jQuery prefers 
$('#theId'). Also, attr(key) in jQuery is readAttribute(key) in Prototype.

Walter

> 
> On 24 Okt., 11:25, radhames brito <[email protected]> wrote:
>>> Now I want to do that in pure Rails 3 code with a check_box_tag, but I
>>> don't know where to put my jquery code. I already watched the Railcast
>>> episode about jquery, but that didn't helped me at all!
>> 
>> uff , your code is messy. ok here it goes. since the form is only to render
>> the check_boxes you can leave it as it is but add an id to it
>> 
>> <form id=>"filters">
>> 
>> and checkboxes
>> 
>> check_box_tag  'show1', 'show'
>> check_box_tag  'show2', 'show'
>> check_box_tag  'showall', 'show'
>> 
>> then in your application.js file (rails 3.0.x)
>> 
>> $("#filter input:checkbox").click(function(){
>>    class_to_show =  $(this).attr("id");
>>   switch(class_to_show){
>>       case 'show1':
>>          $(".show1").show();
>>          $(".show2").hide();
>>       break;
>>       case 'show2':
>>          $(".show1").hide();
>>          $(".show2").show();
>>       break;
>>       default
>>          $(".show1").show();
>>          $(".show2").show();
>>    }
>> 
>> });
>> 
>> aint that pretty?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to