Ok this is the code I have in my view: <select id="client_gender" name="client[gender]" onChange="<%remote_function( :url => {:action => ''change''}) %>"> <option value="">- Select -</option> <option value="Male">Male</option> <option value="Female">Female</option> </select> now in my change.rjs, I have: if @client_gender.value = ''Male'' page.remove ''client_gender'' page.show ''male_form'' else page.remove ''client_gender'' page.show ''female_form'' end When I click on the option I want in my dropdown, it always shows my ''male_form'' no matter what I pick in the dropdown. How can I fix this? And what If I had like 3 or more options what would I do? Thanks -- 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 -~----------~----~----~----~------~----~------~--~---
hi, you do have a div id called "client_gender" right?, also your needs to be == right? -- 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 -~----------~----~----~----~------~----~------~--~---
mixplate wrote:> hi, you do have a div id called "client_gender" right?, also your > needs to be == right?no my select id="client_gender", and I tried with the == and it didn''t do anything, and Firebug didn''t give me any errors. I have a div id="male_form" and a dive id="female_form" -- 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 @client_gender.value = ''Male'' if @client_gender.value == ''Male''? in your action. -- 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 -~----------~----~----~----~------~----~------~--~---
mixplate wrote:> if @client_gender.value = ''Male'' > > if @client_gender.value == ''Male''? > > > in your action.I''ve tried that and nothing happens when I choose an option, I don''t even get any errors either. -- 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 -~----------~----~----~----~------~----~------~--~---
On 6/13/07, Matthew Lagace <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Ok this is the code I have in my view: > > <select id="client_gender" name="client[gender]" onChange="<%> remote_function( > :url => {:action => ''change''}) %>"> > <option value="">- Select -</option> > <option value="Male">Male</option> > <option value="Female">Female</option> > </select>You have nothing in your remote_function to pass the selected value to the action. You''re using Firebug, so turn on "ShowXMLHttpRequests" so you can see the exact request being sent to the server. You''ll see that "Male" or "Female" are not being sent. You should: 1) Wrap the whole thing in a remote_form_for() call. 2) Use observe_field() to submit the form on the ''change'' event for ''client_gender''> > now in my change.rjs, I have: > > if @client_gender.value = ''Male''This is always true, because you''re assigning ''Male'' to the variable. You want == for an equality test. At that point, it will always be false until you fix the problem above.> page.remove ''client_gender'' > page.show ''male_form'' > else > page.remove ''client_gender'' > page.show ''female_form'' > end > > When I click on the option I want in my dropdown, it always shows my > ''male_form'' no matter what I pick in the dropdown.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Well i guess you use the wrong helper here. Remote-function doesn''t automacigally take the value of the selected option and sends it in params[] i think. You took the code from the Rails API docs i assume. Your controller code might be helpful too You should try observe_field: <select id="client_gender" name="client[gender]"> <option value="">- Select -</option> <option value="Male">Male</option> <option value="Female">Female</option> </select> <% = observe_field "cliend_gender", {:url => {:action => change}, :on => "changed"} This should take the "value" of the <select> tag and pass it in the params hash On 13 Jun., 17:00, Matthew Lagace <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> mixplate wrote: > > if @client_gender.value = ''Male'' > > > if @client_gender.value == ''Male''? > > > in your action. > > I''ve tried that and nothing happens when I choose an option, I don''t > even get any errors either. > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten wrote:> Well i guess you use the wrong helper here. Remote-function doesn''t > automacigally take the value of the selected option and sends it in > params[] i think. You took the code from the Rails API docs i assume. > Your controller code might be helpful too > > You should try observe_field: > > <select id="client_gender" name="client[gender]"> > <option value="">- Select -</option> > <option value="Male">Male</option> > <option value="Female">Female</option> > </select> > <% = observe_field "cliend_gender", {:url => {:action => change}, :on > => "changed"} > > This should take the "value" of the <select> tag and pass it in the > params hash > > On 13 Jun., 17:00, Matthew Lagace <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Ok i''ve tried it with the observe_field and when I select an option and nothing still happens. This is what I get as a response in my firebug console: try { $("client_gender").value().= = "Male"; Element.hide("client_gender"); Element.show("male_form"); } catch (e) { alert(''RJS error:\n\n'' + e.toString()); alert(''$(\"client_gender\").value().= = \"Male \";\nElement.hide(\"client_gender\");\nElement.show(\"male_form\");''); throw e } -- 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 -~----------~----~----~----~------~----~------~--~---
Matthew Lagace wrote:> Ok this is the code I have in my view: > > <select id="client_gender" name="client[gender]" onChange="<%> remote_function( > :url => {:action => ''change''}) %>"> > <option value="">- Select -</option> > <option value="Male">Male</option> > <option value="Female">Female</option> > </select> > end > > When I click on the option I want in my dropdown, it always shows my > ''male_form'' no matter what I pick in the dropdown. > > How can I fix this? And what If I had like 3 or more options what would > I do? > > ThanksHow did you get your @client_gender.value ?? you should just set @client_gender = params[:client][:gender] -- 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 -~----------~----~----~----~------~----~------~--~---
> How did you get your @client_gender.value ?? you should just set > @client_gender = params[:client][:gender]No thats my mistake, I want the <select> id which is "client_gender" so instead I should use page[''client_gender''].value == "Male" -- 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 -~----------~----~----~----~------~----~------~--~---