# RJS Scripting

**URL:** <https://www.ruby-forum.com/t/rjs-scripting/123486>\
**Category:** Rails\
**Created:** [December 18, 2007, 5:10am UTC](https://www.ruby-forum.com/t/rjs-scripting/123486 "2007-12-18T05:10:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![edberner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f9ae1b/32.png) [@edberner](https://www.ruby-forum.com/u/edberner)\
**Post date:** [December 18, 2007, 5:10am UTC](https://www.ruby-forum.com/t/rjs-scripting/123486/1 "2007-12-18T05:10:39Z")

</div>

I’m trying to create a search on the index page where it will take a  
search input and return to the same page. On this page is a list of  
all the search items. So I want to highlight them all with AJAX and  
then leave then in bold permanently. The problem comes in evaluating  
the school and search term. I really have no idea what I’m doing with  
this.

page.select("#alphabet strong").each do |element|  
element.visual\_effect :highlight if @search.include? school  
element.insert\_html _make bold_  
end

### Search schools
\<% form\_remote\_tag :url =\> { :action =\> 'result' } do %\> 

\<%= text\_field\_tag :search, params[:search] %\> \<%= submit\_tag "Search", :name =\> nil %\>

\<% end %\>

### Listing Schools

 \<% 'a'.upto 'z' do |l| %\> \<%= l %\> \<% for school in @schools %\> \<% if school.title.first == l.upcase %\> **\<%= link\_to h (school.title), new\_school\_course\_path(school) %\>** \<% end %\> \<% end %\>   
 \<% end %\>

---

<div class="post-metadata">

**Author:** ![edberner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f9ae1b/32.png) [@edberner](https://www.ruby-forum.com/u/edberner)\
**Post date:** [December 18, 2007, 6:21am UTC](https://www.ruby-forum.com/t/rjs-scripting/123486/2 "2007-12-18T06:21:55Z")

</div>

sounds like you should be using setStyle (a prototype method) to make  
your elements bold, e.g.:

element.setStyle({fontWeight: ‘bold’})

I’m not sure if there’s an RJS wrapper for the setStyle method so I’m  
not entirely sure this will work as written. Something like this will  
definitely work though:

page \<\< “$(#{element}).setStyle({fontWeight:‘bold’});”

… which is kinda the long way around.

---

<div class="post-metadata">

**Author:** ![edberner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f9ae1b/32.png) [@edberner](https://www.ruby-forum.com/u/edberner)\
**Post date:** [December 19, 2007, 6:50am UTC](https://www.ruby-forum.com/t/rjs-scripting/123486/3 "2007-12-19T06:50:32Z")

</div>

It does not work for some reason…

---

<div class="post-metadata">

**Author:** ![edberner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f9ae1b/32.png) [@edberner](https://www.ruby-forum.com/u/edberner)\
**Post date:** [December 19, 2007, 7:03am UTC](https://www.ruby-forum.com/t/rjs-scripting/123486/4 "2007-12-19T07:03:58Z")

</div>

page[‘element’].setStyle({fontWeight: ‘bold’})

On Dec 19, 2007 4:20 PM, edberner [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > not entirely sure this will work as written. Something like this will
> > 
> > > all the search items. So I want to highlight them all with AJAX and  
> > > \<% form\_remote\_tag :url =\> { :action =\> ‘result’ } do %\>

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

---

<div class="post-metadata">

**Author:** ![edberner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f9ae1b/32.png) [@edberner](https://www.ruby-forum.com/u/edberner)\
**Post date:** [December 19, 2007, 7:28am UTC](https://www.ruby-forum.com/t/rjs-scripting/123486/5 "2007-12-19T07:28:31Z")

</div>

I’m not sure this is the code I’m looking for because I’ve tried every  
combination of ‘element’ including  
#alphabet dd  
alphabet dd  
alphabet  
and none of those elements work to change the div. More importantly,  
shouldn’t this change the entire div? I would like to only change  
those that match the search results. My index has two arrays for all  
schools and the search results @search. Is there really just no way to  
pass this to javascript for ajax? Would that be useful? Is what I’m  
implementing just too ridiculous?
