Hi,
I have a project in which I need to have a link_to pass the current
value of one text box to my controller. This link is outside my form,
and I wish to do this without submitting the form (using javascript).
I thought of using something like the following:
<%= link_to “Trade Fax”, trade_items_path(:person_contacted =>
“document.getElementById(reference_trade_items__person_contacted).value();”),
:popup
=> true %>
This however does not evaluate the javascript, and just passes it as a
string. Should I somehow be using a link_to_function?
Thanks for your help
Lundie wrote:
Hi,
I have a project in which I need to have a link_to pass the current
value of one text box to my controller. This link is outside my form,
and I wish to do this without submitting the form (using javascript).
I thought of using something like the following:
<%= link_to “Trade Fax”, trade_items_path(:person_contacted =>
“document.getElementById(reference_trade_items__person_contacted).value();”),
:popup
=> true %>
This however does not evaluate the javascript, and just passes it as a
string. Should I somehow be using a link_to_function?
Thanks for your help
This may or may not be helpful, but I know with link_to_remote you have
an :submit option where you can tell the link to submit the information
contained within a div. You just give the :submit the value of the id
for the div which will then get passed onto the correct method in the
controller. In this way you can make a link behave like a form. Hope
this helps,
-S
On 5 Aug 2008, at 17:27, Lundie wrote:
.getElementById
(reference_trade_items__person_contacted).value();"), :popup
=> true %>
This however does not evaluate the javascript, and just passes it as a
string. Should I somehow be using a link_to_function?
One way or another you have to get your javascript into an onclick (By
the way, if you’ve got prototype loaded a more concise way of saying
that is $F(‘reference_trade_items_person_contacted’). Even if you
don’t have prototype, you’ve currently got some syntax errors in there.
One way would be something like
link_to “Trade Fax”, trade_items_path, :onclick => “this.href += ‘?
person_contacted=’ +
encodeURIComponent($F(‘reference_trade_items_person_contacted’));
return true”
This won’t do the right thing if you want it to open in a popup window
- that already sets an onclick. you’d need an onclick that looked
like “window.open(this.href + ‘?person_contacted=’ +
encodeURIComponent($F(‘reference_trade_items_person_contacted’));
return false”
(“person_contacted=’ +
encodeURIComponent($F(‘reference_trade_items_person_contacted’)” can
be shortened to $
(‘reference_trade_items_person_contacted’).serialize() but that will
probably result in a different parameter name arriving at your
controller )
Fred
Thanks guys!
I have gone ahead and used this example, and it works great!
“window.open(this.href + ‘?person_contacted=’ +
encodeURIComponent($F(‘reference_trade_items_person_contacted’));
return false”
On Aug 5, 3:43 pm, Frederick C. [email protected]
Lundie wrote:
Thanks guys!
I have gone ahead and used this example, and it works great!
“window.open(this.href + ‘?person_contacted=’ +
encodeURIComponent($F(‘reference_trade_items_person_contacted’));
return false”
On Aug 5, 3:43�pm, Frederick C. [email protected]
I’ve done this with the observe_field prototype helper. Works quite
well actually. It will push the value of the field it’s observing to the
controller.
http://rails-doc.org/rails/ActionView/Helpers/PrototypeHelper/observe_field
I’ve done this with the observe_field prototype helper. Works quite
well actually. It will push the value of the field it’s observing to the
controller.
http://rails-doc.org/rails/ActionView/Helpers/PrototypeHelper/observe_field
Oops didn’t understand the first post. disregard.