Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use onkeyup() method when i am writing my input with "text_field_tag" (ruby on rails)

this is my form:

<%= form_tag('/search/results', :method => "get") do %>
  <%= label_tag(:q, "Search for:") %>
  <%= text_field_tag(:q) %> 
  <%= submit_tag("Search") %>
<% end %>

i want when i start typing in the text field the site wil refresh. how can i do it?

like image 552
gal Avatar asked Jan 23 '26 09:01

gal


1 Answers

If you mean to just add extra HTML attributes to the element generated by text_field_tag, you can pass them as a hash.

<%= text_field_tag(:q, :onkeyup => 'myJSFunctionToHandleStuff()') %> 

Hash arguments other than :disabled, :size, :maxlength, :placeholder are treated just as passthrough HTML attributes onto the generated input element

like image 136
madlep Avatar answered Jan 25 '26 22:01

madlep



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!