I'm working on Rails application.
If you click on that button, it automatically input @keyword into body_input
I want it with link_to instead of button_to.
How can I?
View
<%= button_to "Populate the chat box", "#name", :id => :username, :value => @keyword %>
jQuery
$(document).ready(function(e) {
$('button#username').click(function () {
e.preventDefault();
$(".chat_input#body_input").val($(this).attr('value'));
});
});
Additional Info(This is output javascript in HTML)
<script type="text/javascript">
//<![CDATA[
$(document).ready(function(e) {
$('button#username').click(function () {
e.preventDefault();
$(".chat_input#body_input").val($(this).attr('value'));
});
});
//]]>
</script>
I am not familiar wit ROR syntax but try this:
and (Id must be unique so in the jquery selector on ID refrain from using tagname#Id just use ID)
The following two are equivalent in function, though not in markup:
As commenter PSL astutely points out, if you decide to utilize a
link_to
to jump to a named anchor, you'll need to modify your jQuery function to removee.preventDefault()
: