I'm sorry, I have just fixed the code as follow:
(function() {
$("#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();
}
})});
On Mon, Oct 24, 2011 at 9:25 PM, Sebastian
<[email protected]>wrote:
> EDIT: The error is in the line after the "default"
>
> On 24 Okt., 16:23, Sebastian <[email protected]> wrote:
> > With the modified code, Firebug gives me that error:
> > missing : after case label
> > $(".show1").show();
> >
> > Code in application.js looks like this now:
> >
> > (function() {
> > $("#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();
> > }
> > }));
> >
> > I tried it with and without that tag inmyview:
> > <%= javascript_include_tag "http://code.jquery.com/jquery-latest.js"
> > %>
> >
> > That should include JQuery, right?
> >
> > On 24 Okt., 16:01, Walter Lee Davis <[email protected]> wrote:
> >
> >
> >
> >
> >
> >
> >
> > > 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 inmypublic/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();
> > > > }
> >
> > > > });
> >
> > > >Myformis looking like that:
> >
> > > > <formid="filters">
> > > > <%= check_box_tag 'show1', 'show' %>
> > > > <%= check_box_tag 'show2', 'show' %>
> > > > <%= check_box_tag 'showall', 'show' %>
> > > > </form>
> >
> > > > Andmytable 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 pureRails3code with a check_box_tag, but I
> > > >>> don't know where to putmyjquery 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 theformis only to
> render
> > > >> the check_boxes you can leave it as it is but add an id to it
> >
> > > >> <formid=>"filters">
> >
> > > >> and checkboxes
> >
> > > >> check_box_tag 'show1', 'show'
> > > >> check_box_tag 'show2', 'show'
> > > >> check_box_tag 'showall', 'show'
> >
> > > >> then in your application.js file (rails3.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 onRails: 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 athttp://
> 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.
>
>
--
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.