Change field value

21 views
Skip to first unread message

Euan Leslie

unread,
Nov 16, 2015, 8:10:13 AM11/16/15
to rubyonra...@googlegroups.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

Help is very much appreciated.

--
Posted via http://www.ruby-forum.com/.

Paulo Geyer

unread,
Nov 16, 2015, 8:25:05 AM11/16/15
to Euan Leslie, rubyonra...@googlegroups.com

John Lahr

unread,
Nov 16, 2015, 7:38:38 PM11/16/15
to Ruby on Rails: Talk
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"

Rahoul Baruah

unread,
Nov 18, 2015, 12:55:16 PM11/18/15
to Ruby on Rails: Talk
Hi


On Monday, 16 November 2015 13:10:13 UTC, Ruby-Forum.com User wrote:
 
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)
Reply all
Reply to author
Forward
0 new messages