Forum: Ruby on Rails RE: button_to execute javascript function

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E3be3af92e8756ffe1f940ac5fd57129?d=identicon&s=25 torben.wolm (Guest)
on 2005-11-22 21:48
(Received via mailing list)
I think you can use one of:

<%= link_to_function "Add Row", "addRow()" %>

<%= tag "input", { "type" => "button", "value" => "Add Row", "onclick"
=> "addRow()" } %>

<%= button_to "Add Row", "javascript:addRow()" %>

Best regards,

torben



	-----Original Message-----
	From: rails-bounces@lists.rubyonrails.org
[mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Damon Hill
	Sent: 22. november 2005 20:38
	To: rails@lists.rubyonrails.org
	Subject: [Rails] button_to execute javascript function


	Ok, I know this has to be EXTREMELY simple, so please excuse the
ignorance.

	However, I want the button_to method to execute some external
javascript function I have predefined called "addRow()" when the user
clicks the button.

	I see all these examples of button_to .... :confirm => "Are you sure?",
but that is the ONLY example I see for button_to html_options.

	I attempted this button_to ....:onclick => "addRow()", but it appends
this to the url ?onclick=addRow().

	Anyone? Anyone?

	Show me just how dumb I am this afternoon.
	It won't hurt my feelings in the least.

	Thanks in advance.
	~d
This topic is locked and can not be replied to.