Hi, I have a text field as: <%= text_field :contact ,:name,:class=>''roundRect'',:id=>''name'' %> Then on click of a link I want to pass the value in this text field to a controller method. I do not want to use a form and form submit. I have the link as: <a href ="/main/search" >GO</a> and to this ''search'' method I want to pass the text field value.... How do I do 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 -~----------~----~----~----~------~----~------~--~---
Hello, you may add javascript to onclick event of your link. <a href ="/main/search" onclick="return addParam(this);">GO</a> and in js file : function addParam(link){ var name = $(''name''); if(name && !name.value.blank()){ link.href += ''''?query=" + escpe(name.value); return true; } else { alert(''Input string for search''); return false; } } then in your controller use params[:query] --~--~---------~--~----~------------~-------~--~----~ 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 Jeba, On Fri, 2009-03-06 at 06:55 +0100, Jeba Momin wrote:> Hi, > I have a text field as: > <%= text_field :contact ,:name,:class=>''roundRect'',:id=>''name'' %> > > Then on click of a link I want to pass the value in this text field to a > controller method. > I do not want to use a form and form submit. > > I have the link as: > <a href ="/main/search" >GO</a> > and to this ''search'' method I want to pass the text field value.... > > How do I do this??? > Thank you...The link_to_remote helper will do what you want. First, you need to wrap the field(s) you want to pass to the controller in a <div> with an id. <div id=''field_to_submit''> <%= text_field :contact ,:name,:class=>''roundRect'',:id=>''name'' %> </div> Then in your link_to_remote ... <%= link_to_remote ''Click me'', :url => (:controller => ''main'', :action => ''search}, :submit => ''field_to_submit'', :method => :post %> When the link is clicked, the value you''re looking for will be passed to the controller via a POST and can be accessed using params[:contact][:name] HTH, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rakoth wrote:> Hello, you may add javascript to onclick event of your link. > > <a href ="/main/search" onclick="return addParam(this);">GO</a> >Hi Thank for helping. I tried this..but the problem I''m facing is that,the first time I click the link is as: http://localhost:3000/main/search On the second click the link is as: http://localhost:3000/main/search?query=<text_field_value> On the thirdclick the link is as: http://localhost:3000/main/search?query=<text_field_value>?query=<text_field_value> and so on.... Can u please suggest how do I solve this??? I''m not well versed with javascripts.... Thank you again.... bill walton wrote:> <%= link_to_remote ''Click me'', :url => (:controller => ''main'', :action > => ''search}, :submit => ''field_to_submit'', :method => :post %> > > When the link is clicked, the value you''re looking for will be passed to > the controller via a POST and can be accessed using > params[:contact][:name]Thank you for your help.. But it didn''t work for me.... :( My code looks as: <div id=''srchname''> <%= text_field :contact ,:name,:class=>''roundRect'',:id=>''name'' %> </div> <%=link_to_remote(''Go'', :url =>{:controller => ''main'', :action=> ''search''},:submit => ''srchname'',:method =>''post'')%> But it doesn''t even go to the main/search method... Where am I going wrong??? 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 -~----------~----~----~----~------~----~------~--~---
I can''t really say what went wrong with the previous code you tried, but here is how i would do it: <%= text_field :contact ,:name,:class=>''roundRect'',:id=>''name'' %> <%=link_to_remote(''Go'', :url =>{:controller => ''main'', :action=> ''search''}, :with => "''contact[name]='' + $(''contact_name'').value")%> @bill walton: Can you use the :submit parameter of link_to_remote even without wrapping the inputs in form tag? The documentation seems to suggest so, but i''ve never tried .... On Mar 9, 7:28 am, Jeba Momin <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Rakoth wrote: > > Hello, you may add javascript to onclick event of your link. > > > <a href ="/main/search" onclick="return addParam(this);">GO</a> > > Hi > Thank for helping. > I tried this..but the problem I''m facing is that,the first time I click > the link is as:http://localhost:3000/main/search > On the second click the link is as:http://localhost:3000/main/search?query=<text_field_value> > On the thirdclick the link is as:http://localhost:3000/main/search?query=<text_field_value>?query=<text_field_value> > and so on.... > Can u please suggest how do I solve this??? > I''m not well versed with javascripts.... > Thank you again.... > > bill walton wrote: > > <%= link_to_remote ''Click me'', :url => (:controller => ''main'', :action > > => ''search}, :submit => ''field_to_submit'', :method => :post %> > > > When the link is clicked, the value you''re looking for will be passed to > > the controller via a POST and can be accessed using > > params[:contact][:name] > > Thank you for your help.. > But it didn''t work for me.... :( > My code looks as: > <div id=''srchname''> > <%= text_field :contact ,:name,:class=>''roundRect'',:id=>''name'' %> > </div> > <%=link_to_remote(''Go'', :url =>{:controller => ''main'', :action=> > ''search''},:submit => ''srchname'',:method =>''post'')%> > > But it doesn''t even go to the main/search method... > Where am I going wrong??? > Thank You. > -- > 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 -~----------~----~----~----~------~----~------~--~---
Hi Felix, On Mon, 2009-03-09 at 05:34 -0700, Felix wrote:> @bill walton: Can you use the :submit parameter of link_to_remote even > without wrapping the inputs in form tag? The documentation seems to > suggest so, but i''ve never tried ....So give it a try! [straight answer => yes ;-) ] --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---