# Adding javascript to f.text\_field

**URL:** <https://www.ruby-forum.com/t/adding-javascript-to-f-text-field/140560>\
**Category:** Rails\
**Created:** [June 16, 2008, 9:37am UTC](https://www.ruby-forum.com/t/adding-javascript-to-f-text-field/140560 "2008-06-16T09:37:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![splashlin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@splashlin](https://www.ruby-forum.com/u/splashlin)\
**Post date:** [June 16, 2008, 9:37am UTC](https://www.ruby-forum.com/t/adding-javascript-to-f-text-field/140560/1 "2008-06-16T09:37:04Z")

</div>

In a current project of mine I have a div field that is located behind  
a text\_field that is acting like a row in a table. Whenever someone  
hovers over the whitespace in the row the background color changes.  
However, when they click the text area in the row the highlight  
disappears. I would like the highlight to remain when the text\_box is  
the focus. I know how to write the javascript for this, but I don’t  
know where to put it in the code.

Code:

\<%= f.text\_field :email, :size =\> 30 %\>

Thanks

---

<div class="post-metadata">

**Author:** ![splashlin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@splashlin](https://www.ruby-forum.com/u/splashlin)\
**Post date:** [June 17, 2008, 6:59pm UTC](https://www.ruby-forum.com/t/adding-javascript-to-f-text-field/140560/2 "2008-06-17T18:59:10Z")

</div>

you can pass other html attributes similar to :size, e.g.

\<%= f.text\_field :email, :size =\> 30, :onchange =\> ‘…’, :onfocus=\>  
‘…’ %\>

etc.

personally, I like to use lowpro

[http://www.danwebb.net/2006/9/3/low-pro-unobtrusive-scripting-for-prototype](http://www.danwebb.net/2006/9/3/low-pro-unobtrusive-scripting-for-prototype)

which lets me extact scripting to a .js file and clean up my views
