Greetings to you, I''m trying to write a "preview" link, and need to pass along the current value of a text_field to this link. I figure there is some simple Javascript way to do this, but so far haven''t figured it out. Does anyone know how to get and pass the current value of a text_field to link_to? -- 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 -~----------~----~----~----~------~----~------~--~---
FWIW, I''m opening "preview" in another window. For right now, I plan on passing the current value of the text_field by setting params[:body] equal to it, but that doesn''t seem to be the best idea. Is there a better way to pass the current value to the "preview" 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 -~----------~----~----~----~------~----~------~--~---
Where is the value in the text field coming from? If it''s coming from your app (e.g. from the database or from a user passing parameters), then you can do this on the Rails side of things, and it seems most likely that you want to set an instance variable in the controller (e.g. @text_field_value = [value]), which you can then use in both your link_to and text_field. If you want the text field to dynamically update as the value of the text field is changed, then you should use Javascript, such as something along these lines: <input type="text" onkeyup="$(''link'').innerHTML = this.value" /> <a href="preview..." id="link"> Default text </a> Best of luck, Greg On Jan 27, 12:54 pm, Joe Peck <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> FWIW, I''m opening "preview" in another window. > > For right now, I plan on passing the current value of the text_field by > setting params[:body] equal to it, but that doesn''t seem to be the best > idea. Is there a better way to pass the current value to the "preview" > action? > -- > 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 -~----------~----~----~----~------~----~------~--~---
Greg wrote:> Where is the value in the text field coming from?It''s coming from whatever the user is typing in, so not from the database :(> If you want the text field to > dynamically update as the value of the text field is changed, then you > should use Javascript, such as something along these lines: > > <input type="text" onkeyup="$(''link'').innerHTML = this.value" /> > <a href="preview..." id="link"> Default text </a>Thanks, that''s almost what I''m looking for. I''m having trouble passing the value of link to the "preview" action... instead, when I hit "preview" now, it shows value of the text field below the text field. I guess I just need to set the value of a ruby variable equal to link.innerHTML somehow... -- 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 -~----------~----~----~----~------~----~------~--~---
Man, maybe I am making this more complicated than it should be. I just need to pass whatever is in the text_field to a "preview" action when I click a "preview" link. So I don''t really need to dynamically update anything, but when "preview" is clicked, I want to get what is in the text_field and pass it to my "preview" action. To make it clearer, when someone clicks "Preview Post", I want @body to be set to whatever is in the text_field. <%= link_to "Preview Post", {:action => :preview, :id => @topic.id, :body => @body}, {:id => ''link'', :target => "_blank"} %> Any ideas? -- 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 -~----------~----~----~----~------~----~------~--~---
> <%= link_to "Preview Post", {:action => :preview, :id => @topic.id, > :body => @body}, {:id => ''link'', :target => "_blank"} %>try this: <%= link_to "Preview Post", {:action => :preview, :id => @topic.id}, {:onclick => "this.href +=''?body=''+encodeURIComponent($F (''id_of_the_form_element'')); return true", :id => ''link'', :target => "_blank"} %> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
John Yerhot wrote:>> <%= link_to "Preview Post", {:action => :preview, :id => @topic.id, >> :body => @body}, {:id => ''link'', :target => "_blank"} %> > > try this: > > <%= link_to "Preview Post", {:action => :preview, :id => @topic.id}, > {:onclick => "this.href +=''?body=''+encodeURIComponent($F > (''id_of_the_form_element'')); return true", :id => ''link'', :target => > "_blank"} %>Muchas gracias, that is close to perfect. The only problem is if I hit "Preview Post" multiple times, it keeps adding onto body, but I can fix that problem. It''s times like these that I realize I need to learn more javascript. -- 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 -~----------~----~----~----~------~----~------~--~---
Glad it worked for you. :) On Jan 27, 3:47 pm, Joe Peck <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> John Yerhot wrote: > >> <%= link_to "Preview Post", {:action => :preview, :id => @topic.id, > >> :body => @body}, {:id => ''link'', :target => "_blank"} %> > > > try this: > > > <%= link_to "Preview Post", {:action => :preview, :id => @topic.id}, > > {:onclick => "this.href +=''?body=''+encodeURIComponent($F > > (''id_of_the_form_element'')); return true", :id => ''link'', :target => > > "_blank"} %> > > Muchas gracias, that is close to perfect. The only problem is if I hit > "Preview Post" multiple times, it keeps adding onto body, but I can fix > that problem. > > It''s times like these that I realize I need to learn more javascript. > -- > 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 -~----------~----~----~----~------~----~------~--~---
John Yerhot wrote:> try this: > > <%= link_to "Preview Post", {:action => :preview, :id => @topic.id}, > {:onclick => "this.href +=''?body=''+encodeURIComponent($F > (''id_of_the_form_element'')); return true", :id => ''link'', :target => > "_blank"} %>Hi John, I have a similar requirement. I need to pass the value of a text field with link_to What I''m doing is: <%= link_to "Go", {:controller=>''main'',:action=>''searchcontc''},:onclick => "this.href +=''?uname=''+encodeURIComponent($F(''name'')); return true" %> But this doesn''t work properly. The first time I click the link it redirects to: http://localhost:3000/main/searchcontc And on the second click it goes to: http://localhost:3000/main/searchcontc?uname=<value_of_text_filed> Can please help me..and let me know how do I correct this... Thank you. -- 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:> Muchas gracias, that is close to perfect. The only problem is if I hit > "Preview Post" multiple times, it keeps adding onto body, but I can fix > that problem. > > It''s times like these that I realize I need to learn more javascript.Hi Joe Can u please share wid me how did u solve ur problem??? I''m too facing d same problem. The parameter gets added every time I click the link..!!!! How did u correct it??? Thank you... -- 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 -~----------~----~----~----~------~----~------~--~---