Change field value

Hi

I want to change the value of a field when another field is updated.

Specifically, I want my e mail field to get it's data from the username,
the domain always being the same, so username is say johndoe, e mail
address will be johndoe@wherever.com

my fields look like this:

    <p><h3><label class="field" for="username">Username:</label></h3>
    <%= f.text_field :username, :style => "width: 250px" %></p>

    <p><h3><label class="field" for="email">Email Address:</label></h3>
    <%= f.text_field :email, :style => "width: 250px" %></p>

Very much a beginner with JavaScript incidentally so be gentle

Help is very much appreciated.

You can do that using jQuery,

http://stackoverflow.com/questions/12287996/jquery-change-value-when-value-of-other-input-field-is-changed

If the domain name is always the same - why do you need a field for the email address, just determine it dynamically whenever you’re looking at the user

“{#user.username}@whenever.com

Hi

I want to change the value of a field when another field is updated.

Specifically, I want my e mail field to get it’s data from the username,

the domain always being the same, so username is say johndoe, e mail

address will be joh...@wherever.com

my fields look like this:

<p><h3><label class="field" for="username">Username:</label></h3>

<%= f.text_field :username, :style => "width: 250px" %></p>



<p><h3><label class="field" for="email">Email Address:</label></h3>

<%= f.text_field  :email, :style => "width: 250px" %></p>

Very much a beginner with JavaScript incidentally so be gentle

Do you really need to do this with Javascript?

As someone else has said, if the domain is always the same then you only really need to ask for the username. If you want to store the full email address in your database you could add it on server-side in your ruby code (if you’re using Rails then as a before_save callback on the model)