Forum: Ruby on Rails how to call javascript function in text_field_tag

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Valentino L. (Guest)
on 2009-04-17 12:30
Dear all

Sorry for dummy question. How can I convert a text input in form to
upper case letter in view?

Can I call the javascript function toUpperCase() in text_field_tag??
<%= text_field_tag(:sometext, nil, :size => 14) %>

I know I can achieve this using params[:sometext].upcase in controller,
but I want to do this in view. Any ideas?

Many thanks
Charanya N. (Guest)
on 2009-04-17 15:59
<script type="text/javascript">
function changecase()


<%= text_field_tag(:sometext, nil, :size => 14 , :onchange =>
"changecase();") %>

When u enter the text in the textbox and when the focus goes out of the
textbox the text changes to uppercase.

Hope this might help.
Schalk N. (Guest)
on 2009-04-17 16:13
(Received via mailing list)
Hi Charanya,

Or try using unobtrusive JavaScript by giving the field a unique id and
then hooking up the action to that id. With jQuery it is very simple.

To get the field just use:


and then you can chain any function to the element.

This topic is locked and can not be replied to.