Solved

Using JavaScript onblur to populate text fields

Posted on 2004-08-18
5
1,019 Views
Last Modified: 2008-03-03
Hi,
   What i am trying to do is populate a text field with the data that i enter in the previous field.
e.g when i enter a persons name in the first field i want to append, say "@hotmail.com", to it and add the whole value automaticaly to the next text field.

I understand you can do this by using Javascript onBlur but i'm not sure how.

Any help would be much appreciated

Thanks
0
Comment
Question by:mickmurph
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 3

Expert Comment

by:alexpreston
ID: 11829239
something like...

<input type="text" id="txtName" onblur="Append();">
<input type="text" id="txtEmail">

<script>
function Append()
{
txtEmail.text = txtName.text + '@hotmail.com';
}
</script>
0
 
LVL 2

Expert Comment

by:mr_asphalt
ID: 11829429
that should be:
txtEmail.value = txtName.value + '@hotmail.com';
0
 
LVL 3

Expert Comment

by:alexpreston
ID: 11829445
you're quite right, a slap on the wrists for me :)
0
 
LVL 9

Expert Comment

by:riyasjef
ID: 11829458
this is a better method using "onkeypress"

<form name="frm">
      <input type="text" id="txtName" onkeypress="Append(this.value);">
      <input type="text" id="txtEmail">
</form>      

<script>
function Append(str)
{
       document.frm.txtEmail.value=str+'@hotmail.com';

}
</script>
0
 
LVL 3

Accepted Solution

by:
alexpreston earned 100 total points
ID: 11829495
Not sure I'd use onkeypress. I'd consider it overkill to change the email field for every keypress. But it is a valid solution!
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Angular2 remove duplicates 11 19
Error Handler 8 38
display data from multiple ajax calls 9 35
Angular - difference between these 2 codes 3 12
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question