diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb
index 7dccecda13b009c4f2e5be48496a170f1dfc1e20..3be96db00135f7b06c8af24179e8b364780250cb 100644
--- a/actionpack/lib/action_view/helpers/javascript_helper.rb
+++ b/actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -53,7 +53,7 @@ def link_to_function(name, function, html_options = {})
"a", name,
html_options.merge({
:href => html_options[:href] || "#",
- :onclick => "#{function};#{html_options[:onclick] ? " #{html_options[:onclick]};" : ""} return false;"
+ :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function}; return false;"
})
)
end
diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb
index 6a01bd14b2b1ef58a931bb2cae9fc64a90de8e02..ef830e4e98916f7aecb2d83ca1ad82d872382bfb 100644
--- a/actionpack/test/template/javascript_helper_test.rb
+++ b/actionpack/test/template/javascript_helper_test.rb
@@ -27,7 +27,7 @@ def test_link_to_function
end
def test_link_to_function_with_existing_onclick
- assert_dom_equal %(Greeting),
+ assert_dom_equal %(Greeting),
link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')")
end
end