Hi, can''t find a solution for this. Have a series of <li>''s. When the user clicks on one of them, a second series shows in a updated, other <div>. Works fine with RJS. But: I''d like to change the background-color for the <li> clicked in the first list, so the user can always see and remember which one of the first list he actually has chosen. Sounds simple, but I can''t figure it out. I''ve tried a few :onclick javascript solutions, but they obviously weren''t solutioons at all. :- ( Could anybody give me a few hints or so? Thanks in advance. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jul 3, 10:02 pm, Rudy <rsoete...-CNXmb7IdZIWZIoH1IeqzKA@public.gmane.org> wrote:> Hi, can''t find a solution for this. Have a series of <li>''s. When the > user clicks on one of them, a second series shows in a updated, other > <div>. Works fine with RJS. > But: I''d like to change the background-color for the <li> clicked in > the first list, so the user can always see and remember which one of > the first list he actually has chosen. > Sounds simple, but I can''t figure it out. I''ve tried a few :onclick > javascript solutions, but they obviously weren''t solutioons at all. :-You could just add a class to the first li (you could do that with your rjs). If you show what you''ve tried someone might be able to point out where it''s going wrong. Fred> ( Could anybody give me a few hints or so? Thanks in advance.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, I have a partial with this code <%@cups.each do |cup|%> <li class = "element2" id="<%=cup.id%>"><%link_to_remote(cup.name, :url => {:action =>''add_books_list'', :id => cup.id}) %></li> <%end%> lets say whe have 50 cups. There must be an easy way to change the backgroundcolor on the one <li> that is clicked on, with as little server-activity as possible. I think a javascript-script should do it, but I''m afraid I just don''t have enough knowledge of that. I realise that in a way I have to update the partial, and I''m trying to find an example that could show me, but I just can''t find it. (Or maybe I just think it is easy, but it isn''t.) Thanks for any help anyway. Really appreciate it. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, Jul 3, 2008 at 2:48 PM, Rudy <rsoetewey-CNXmb7IdZIWZIoH1IeqzKA@public.gmane.org> wrote:> lets say whe have 50 cups. There must be an easy way to change the > backgroundcolor on the one <li> that is clicked on, with as little > server-activity as possible.How about none? :-) Briefly tested in FF2/OS X -- requires prototype.js -- <script type="text/javascript"> var listitems; function choose(e) { $A(listitems).each( function(li){ li.removeClassName("chosen"); } ); Event.element(e).addClassName("chosen"); } function init() { listitems = document.getElementsByTagName("li"); /* you may need to identify a subset of these */ $A(listitems).each( function(li){ Event.observe(li, ''click'', choose); } ); } Event.observe(window,''load'', init); </script> <style type="text/css"> .chosen { background-color: red; } </style> HTH, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Absolutely briljant. Many, many thanks. On 4 jul, 00:21, "Hassan Schroeder" <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Jul 3, 2008 at 2:48 PM, Rudy <rsoete...-CNXmb7IdZIWZIoH1IeqzKA@public.gmane.org> wrote: > > lets say whe have 50 cups. There must be an easy way to change the > > backgroundcolor on the one <li> that is clicked on, with as little > > server-activity as possible. > > How about none? :-) > > Briefly tested in FF2/OS X -- requires prototype.js -- > > <script type="text/javascript"> > var listitems; > function choose(e) > { > $A(listitems).each( function(li){ li.removeClassName("chosen"); } ); > Event.element(e).addClassName("chosen");} > > function init() > { > listitems = document.getElementsByTagName("li"); > /* you may need to identify a subset of these */ > $A(listitems).each( function(li){ Event.observe(li, ''click'', choose); } );} > > Event.observe(window,''load'', init); > </script> > <style type="text/css"> > .chosen { background-color: red; } > </style> > > HTH, > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 04 Jul 2008, at 00:21, Hassan Schroeder wrote:>> lets say whe have 50 cups. There must be an easy way to change the >> backgroundcolor on the one <li> that is clicked on, with as little >> server-activity as possible. > > How about none? :-) > > Briefly tested in FF2/OS X -- requires prototype.js -- > > <script type="text/javascript"> > var listitems; > function choose(e) > { > $A(listitems).each( function(li){ li.removeClassName("chosen"); } ); > Event.element(e).addClassName("chosen"); > } > function init() > { > listitems = document.getElementsByTagName("li"); > /* you may need to identify a subset of these */ > $A(listitems).each( function(li){ Event.observe(li, ''click'', > choose); } ); > } > Event.observe(window,''load'', init); > </script> > <style type="text/css"> > .chosen { background-color: red; } > </style>And even better would be to wrap this code in a Javascript object (which prototype conveniently disguises as a Class.create();) instead of using simple functions (that''s just as bad as most of the hobby PHP projects you see out there IMHO) and use event delegation. This method will fail as soon as you add list items to the bottom of the list using ajax (since the click event won''t be bound to the new element), forcing you to call the init method again. Also, you are binding an event to each list element, which is quite an expensive operation, and it certainly will become a problem if you have tens to hundreds of these listitems on a page. Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Use javascript , get id and assign a class name . =========CJ(JON) Peter De Berdt wrote:> On 04 Jul 2008, at 00:21, Hassan Schroeder wrote: > > >> lets say whe have 50 cups. There must be an easy way to change the > >> backgroundcolor on the one <li> that is clicked on, with as little > >> server-activity as possible. > > > > How about none? :-) > > > > Briefly tested in FF2/OS X -- requires prototype.js -- > > > > <script type="text/javascript"> > > var listitems; > > function choose(e) > > { > > $A(listitems).each( function(li){ li.removeClassName("chosen"); } ); > > Event.element(e).addClassName("chosen"); > > } > > function init() > > { > > listitems = document.getElementsByTagName("li"); > > /* you may need to identify a subset of these */ > > $A(listitems).each( function(li){ Event.observe(li, ''click'', > > choose); } ); > > } > > Event.observe(window,''load'', init); > > </script> > > <style type="text/css"> > > .chosen { background-color: red; } > > </style> > > And even better would be to wrap this code in a Javascript object > (which prototype conveniently disguises as a Class.create();) instead > of using simple functions (that''s just as bad as most of the hobby PHP > projects you see out there IMHO) and use event delegation. This method > will fail as soon as you add list items to the bottom of the list > using ajax (since the click event won''t be bound to the new element), > forcing you to call the init method again. Also, you are binding an > event to each list element, which is quite an expensive operation, and > it certainly will become a problem if you have tens to hundreds of > these listitems on a page. > > > Best regards > > Peter De Berdt--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Fri, Jul 4, 2008 at 2:19 AM, Peter De Berdt <peter.de.berdt-LPO8gxj9N8aZIoH1IeqzKA@public.gmane.org> wrote:> And even better would be to wrap this code in a Javascript object (which > prototype conveniently disguises as a Class.create();) instead of using > simple functions (that''s just as bad as most of the hobby PHP projects you > see out there IMHO) and use event delegation. This method will fail as soon > as you add list items to the bottom of the list using ajax (since the click > event won''t be bound to the new element), forcing you to call the init > method again. Also, you are binding an event to each list element, which is > quite an expensive operation, and it certainly will become a problem if you > have tens to hundreds of these listitems on a page.Wildly overkill for the OP''s situation, I think :-) but a valid point for some circumstances. Still, if you have hundreds of list items on a page, I''d be worrying more about the basic IA (or lack thereof)... -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---