Good afternoon to you all, I have an order form where people can check the fruits they want and select the price of each fruit that they have checked. When I click the checkbox now, it does not seem to affect the corresponding price dropdown. What am I doing wrong? Here''s the javascript: <script type="text/javascript"> function toggle_fruit_price(lqname) { $(lqname).disabled = (!$(lqname).disabled); } </script> Then, inside my loop of @fruits: <%= fruit.name %> <%= check_box_tag fruit.name, 1, false, :onchange => "toggle_fruit_price(#{fruit.name}_price);" %> <%= select_tag("#{fruit.name}_price", options_for_select((0..100))) %> Does anyone see what I''m doing wrong? Any help is appreciated. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Dec-03 19:10 UTC
Re: Check a checkbox and disable a field with Javascript
On 3 Dec 2008, at 19:07, Joe Peck wrote:> > Good afternoon to you all, > > I have an order form where people can check the fruits they want and > select the price of each fruit that they have checked. > > When I click the checkbox now, it does not seem to affect the > corresponding price dropdown. What am I doing wrong? > > Here''s the javascript: > <script type="text/javascript"> > function toggle_fruit_price(lqname) { > $(lqname).disabled = (!$(lqname).disabled); > } > </script> > > Then, inside my loop of @fruits: > <%= fruit.name %> > <%= check_box_tag fruit.name, 1, false, :onchange => > "toggle_fruit_price(#{fruit.name}_price);" %> > <%= select_tag("#{fruit.name}_price", options_for_select((0..100))) %> >If you think of the javascript that will be generated it''s just going to be toggle_fruit_price(apple_price); whereas you want it to be toggle_fruit_price(''apple_price''); Fred> Does anyone see what I''m doing wrong? Any help is appreciated. > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> If you think of the javascript that will be generated it''s just going > to be > > toggle_fruit_price(apple_price); > > whereas you want it to be > > toggle_fruit_price(''apple_price''); > > > FredHmm, well I have also tried <script type="text/javascript"> function toggle_weight_boxes(lqname) { $(''lqname'').disabled = (!$(''lqname'').disabled); } </script> and that doesn''t work. I''m sure I''m only a tiny bit off, how else should I write this? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Joe Peck wrote:> Good afternoon to you all, > > I have an order form where people can check the fruits they want and > select the price of each fruit that they have checked. > > When I click the checkbox now, it does not seem to affect the > corresponding price dropdown. What am I doing wrong? > > Here''s the javascript: > <script type="text/javascript"> > function toggle_fruit_price(lqname) { > $(lqname).disabled = (!$(lqname).disabled); > } > </script> > > Then, inside my loop of @fruits: > <%= fruit.name %> > <%= check_box_tag fruit.name, 1, false, :onchange => > "toggle_fruit_price(#{fruit.name}_price);" %> > <%= select_tag("#{fruit.name}_price", options_for_select((0..100))) %> > > Does anyone see what I''m doing wrong? Any help is appreciated.Maybe you can try somthing like this: if $(''lqname'').checked == "1" $(''fruit_price_field'').show() -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Dec-03 19:37 UTC
Re: Check a checkbox and disable a field with Javascript
On Dec 3, 7:19 pm, Joe Peck <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > If you think of the javascript that will be generated it''s just going > > to be > > > toggle_fruit_price(apple_price); > > > whereas you want it to be > > > toggle_fruit_price(''apple_price''); > > > Fred > > Hmm, well I have also tried > <script type="text/javascript"> > function toggle_weight_boxes(lqname) { > $(''lqname'').disabled = (!$(''lqname'').disabled); > } > </script> > > and that doesn''t work. I''m sure I''m only a tiny bit off, how else > should I write this?That wasn''t the problem - the toggle_fruit_price function was fine as it was. The problem is with this statement toggle_fruit_price(apple_price); Forget that it''s js for a second - that statement isn''t legal if there is no variable named apple_price, which there isn''t Fred> -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> That wasn''t the problem - the toggle_fruit_price function was fine as > it was. The problem is with this statement > > toggle_fruit_price(apple_price); > > Forget that it''s js for a second - that statement isn''t legal if there > is no variable named apple_price, which there isn''t > > FredPhew, thanks. Javascript is not my forte, but I''m learning more of it now. Thanks for the help :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---