# Javascript in text field with autocomplete

**URL:** <https://www.ruby-forum.com/t/javascript-in-text-field-with-autocomplete/178127>\
**Category:** Rails\
**Created:** [October 29, 2009, 3:31pm UTC](https://www.ruby-forum.com/t/javascript-in-text-field-with-autocomplete/178127 "2009-10-29T15:31:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![RVince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/4491bb/32.png) [@RVince](https://www.ruby-forum.com/u/RVince)\
**Post date:** [October 29, 2009, 3:31pm UTC](https://www.ruby-forum.com/t/javascript-in-text-field-with-autocomplete/178127/1 "2009-10-29T15:31:17Z")

</div>

If I am using the autocomplete plugin, and I have a text field  
specified in a form that incorporates autocomplete, such as:

\<%=  
text\_field\_with\_auto\_complete :doctor, :organization, :autocomplete =\>  
“off” %\>

how can I put javascript event handlers to if (e.g. keypress,  
onchange, etc.) ? WHat I really want to do is call a method in my  
controller if either:

1. The text field is empty, and previously was not -or-
2. The text field is now not empty, and previously was empty.

Thanks, RVince
