access input field id inside erb code

1 view
Skip to first unread message

Dieter D'haeyere

unread,
Aug 23, 2007, 8:11:35 PM8/23/07
to rubyonra...@googlegroups.com
This is the simplified code :

<input type="text" id="activity_lookup" name="activity_lookup" />
<div class="auto_complete" id="activity_lookup_auto_complete"></div>

<%= link_to ' Search ', :action => 'show_activity', :name => ???%>

I would like to pass the name as a parameter to my action. The name
should be the value of the input field with id 'activity_lookup'.
I did not find a solution on how to do this :s
include javascript ? javascipt_tag ? (tried this, but did not do the job
... )

As you will guess : I am using this bit of code for an auto complete
field (example from the rails recipes book)

Is there a nice way to do this ?
Am I looking in the wrong direction and is it much easier ?

Thx for your help.
--
Posted via http://www.ruby-forum.com/.

raghukumar

unread,
Aug 24, 2007, 1:01:42 AM8/24/07
to Ruby on Rails: Talk
Hi Dieter,

this is working for me:

<%= link_to 'Search', {:action => 'show_activity', :name => 'Dieter' }
%>

Note: Check how to pass arguments to "link_to" in http://api.rubyonrails.org/
In your case it's take name as the html_options so it will rendered as
an attribute of <a> tag like this
<a href="http://example.com/controller/some_action" name="dieter"/>

I guess this answers your question.


On Aug 24, 5:11 am, Dieter D'haeyere <rails-mailing-l...@andreas-

Dieter D'haeyere

unread,
Aug 24, 2007, 2:48:39 AM8/24/07
to rubyonra...@googlegroups.com

> <%= link_to 'Search', {:action => 'show_activity', :name => 'Dieter' }
> %>


this was not what I meant.
I want to pass the value of the input field with id "activity_lookup"
Whay you are saying is something very static.

I was thinking in the direction of :
:name => javascript_tag('document.elementById("activity_lookup").value')

But that doesn't work.

The 'name' I want to pass is the value of the input field ...

Reply all
Reply to author
Forward
0 new messages