I posted a question earlier but it didn''t come out that clear and I have spent the whole day looking this up. Any help would be much appreciated. Here goes round 2: I have several textareas on the screen (anywhere from 1 - 5). Right now I have them in a form and am using a submit button to pass the values to the controller. What I need to do is pass these values to the controller using links located outside of the actual form. When the link is click the values from the textareas are passed to the controller along with a :question parameter. The values of the textareas are saved into the db and the :question param is used in a query and then the page is redirected to another page with the result from the query as another param. The part I cannot seem to find an answer for is how to pass the values of the textareas to the controller using link_to(), not link_to_remote. Or how do you access the textarea values and attach them to :value1 => ???? I really hope that made more sense. Thanks, Chris -- 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 Jun 3, 11:46 pm, Chris Hickman <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> The part I cannot seem to find an answer for is how to pass the values > of the textareas to the controller using link_to(), not link_to_remote. > Or how do you access the textarea values and attach them to :value1 => >It''s got to either be javascript or a form submit(and you need javascript to trigger that from a regular link). Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I initially tried it with a remote_function and used that with an onunload event but it would only work 50% of the time. I also tried onclick with the same remote_function but I think the responses were too long and it would only grab half of it before moving on. Oh well, I guess I am going to have to say I can''t do it the way they want it. Thanks anyways, chris -- 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 -~----------~----~----~----~------~----~------~--~---
Sorry I misread your response. How would I trigger the form submit from a link? That is what I have been looking to do all day and could only find ajaxy ways of doing it which wouldnt allow me to redirect afterwards. -- 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 Jun 4, 12:04 am, Chris Hickman <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Sorry I misread your response. How would I trigger the form submit from > a link? That is what I have been looking to do all day and could only > find ajaxy ways of doing it which wouldnt allow me to redirect > afterwards.onclick="some_form.submit()". At that point you might as well just be styling the form''s submit button to not look like a button. Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
So you''ve got a traditional form generated by form_for, with the expected submit button etc. That all works just as you want it to. Now you want to *in addition to the existing submit button* offer a link up at the top of the page that will submit that same form. Do you want that link to a) have exactly the same effect as the submit button--no more, no less, or b) have the same effect as the submit button *plus* tack an extra parameter & value onto :params? (Or c) something else?) If a)--I would think Fred''s earlier suggestion to use javascript to do a my_form.submit() should work. I don''t know the best way to get rails to generate that (link_to_function("click me", "my_form.submit()") maybe?) but no doubt others here will. If b) it''s probably a little more involved (javascript stuffs your parameter in a hidden field created in your form maybe, and *then* does a my_form.submit()?). HTH, -Roy -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Chris Hickman Sent: Tuesday, June 03, 2008 3:47 PM To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails] Accessing form elements I posted a question earlier but it didn''t come out that clear and I have spent the whole day looking this up. Any help would be much appreciated. Here goes round 2: I have several textareas on the screen (anywhere from 1 - 5). Right now I have them in a form and am using a submit button to pass the values to the controller. What I need to do is pass these values to the controller using links located outside of the actual form. When the link is click the values from the textareas are passed to the controller along with a :question parameter. The values of the textareas are saved into the db and the :question param is used in a query and then the page is redirected to another page with the result from the query as another param. The part I cannot seem to find an answer for is how to pass the values of the textareas to the controller using link_to(), not link_to_remote. Or how do you access the textarea values and attach them to :value1 => ???? I really hope that made more sense. Thanks, Chris -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Roy Pardee wrote: or b) have the same effect as the submit button *plus*> tack an extra parameter & value onto :params? (Or c) something else?) >If b) it''s probably a little more> involved (javascript stuffs your parameter in a hidden field created in > your form maybe, and *then* does a my_form.submit()?).Exactly, I need to pass another parameter and that is where I am stuck right now. The only option I can think of is to use some ajax and have it pass a parm in when someone clicks the link and have it return nothing and then have that same click call form.submit() afterwards. I am about to try this now but it seems like 1) it will be really slow and 2) it might not work. We will see. I just dont know a way to pass the extra param as well as submitting the form. Thanks a lot, Chris -- 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 -~----------~----~----~----~------~----~------~--~---
You could simply use a hidden_field -- 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller wrote:> You could simply use a hidden_fieldI could be wrong seeing I am not too familiar with hidden fields but I dont think that would help. I have a list of numbers at the top representing different questions. If the user clicks on "1" I want to pass in the "1" and submit the form, if they click "6" I want to pass in the "6" and submit the form. From what I understand about hidden fields there is no way to pass the "1" or "6" into the hidden field, correct? Chris -- 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 -~----------~----~----~----~------~----~------~--~---
Chris Hickman wrote:> Thorsten Mueller wrote: >> You could simply use a hidden_field > > I could be wrong seeing I am not too familiar with hidden fields but I > dont think that would help. I have a list of numbers at the top > representing different questions. If the user clicks on "1" I want to > pass in the "1" and submit the form, if they click "6" I want to pass in > the "6" and submit the form. From what I understand about hidden fields > there is no way to pass the "1" or "6" into the hidden field, correct? > > Chrisnope, that''s a perfect use case for a hidden field. those numbers should just do some js to set the value of the field -- 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller wrote:> nope, that''s a perfect use case for a hidden field. > those numbers should just do some js to set the value of the fieldOh so it keeps everything client side so it wont be as slow and then the value will get passed in with the form. So, I can just put a call to a javascript method inside the hidden field for :value => and it will get passed through correctly. -- 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 -~----------~----~----~----~------~----~------~--~---
> Oh so it keeps everything client side so it wont be as slow and then the > value will get passed in with the form. So, I can just put a call to a > javascript method inside the hidden field for :value => and it will get > passed through correctly.ok, it depends on how exactly you use the hidden field (and if it''s hidden_field or hidden_field_tag) most simple case: <%= hidden_field_tag ''number'' %> will generate: <input id="number" name="number" type="hidden" /> so the number can define an onchange = "$(''number'').value = ''1''" the id/name may depend on your setup, but just have a look at the generated html to get that. -- 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 -~----------~----~----~----~------~----~------~--~---
That makes sense. Thanks a lot, I really appreciate your help. Chris -- 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 -~----------~----~----~----~------~----~------~--~---