Auto populate a text field based on another text field

Posted by Syed Aslam on Stack Overflow See other posts from Stack Overflow or by Syed Aslam
Published on 2010-04-19T06:58:14Z Indexed on 2010/04/19 7:03 UTC
Read the original article Hit count: 351

Filed under:
|

I am trying to auto-populate a text field based on the value of another input field. Currently trying to do this using observe_field helper like this:

<%= observe_field(
        :account_name, 
        :function => "alert('Name changed!')",
        :on => 'keyup'
    ) %>

<% form_for(@account, :html => { :id => 'theform' }) do |f| %>
    <label for="accountname"> Account name </label>
    <%= form.text_field :name, :tabindex => '1' %>
    <label for="subdomain"> Subdomain </label>
    <%= form.text_field :subdomain, :tabindex => '2' %>
<% end %>

When the user enters text in the account_name text_field, I want to copy that convert into a subdomain (downcase and join by '-') and populate to subdomain text_field.

But, in the process getting this error:

element is null
   var method = element.tagName.toLowerCase();   protot...9227640 (line 3588)

Where exactly am I going wrong here? Or is there a better way to do this?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about JavaScript