On Apr 25, 2013, at 4:41 PM, Brentwood R. wrote:
> ...all instances of "something" will be highlighted in the 'div'. What
> I'm trying to do is make it so that a user can enter a keyword (through
> an input field) so that whatever keyword they entered would be
> highlighted on the page.
OK. This has nothing at all to do with ruby or rails. What you want is a
javascript event handler on the input field which then calls that highlight
function. You'd call something like:
$('div').highlight($('#my_input_field').val())
How you arrange to call that varies, you could set up the event handler
directly as an option in the text_field_tag call in the .html.erb template:
<%= text_field_tag(:my_input_field, '', {onchange: 'call_the_highlight_fun()'})
%>
You could skip the embedded ruby altogether since you're not really using rails
in that little piece and just put in <form> and <input> tags.
Or you could use "unobtrusive javascript", which I prefer: leave the input
field alone, and in a document loaded handler, add the event handler to the
input field:
$(function() {$('#my_input_field').change(function()
{call_the_highlight_fun()})})
Note that:
- I'm whipping this off the top of my head, not all syntax may be correct, but
you seem to be looking for help with the general approach.
- I'm assuming jquery.
- I'm assuming recent rails and ruby 1.9 (thus the {symbol: value} syntax for a
hash).
--
Scott Ribe
[email protected]
http://www.elevated-dev.com/
(303) 722-0567 voice
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.