×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Combine First_Name and Last_Name into Name - Javascript

Combine First_Name and Last_Name into Name - Javascript

Combine First_Name and Last_Name into Name - Javascript

(OP)
Hi all.

New to Javascript. I have a variation of the following script working just fine for calculating a number from two other numbers input into a PHP form but I'm wanting to do the same thing to combine to name fields into a Full Name field.

Hoping someone can help me! Or maybe "keyup" function just doesn't work for non-number fields?

**********************************

var ctrlFirst_Name = Runner.getControl(pageid, 'First_Name');
var ctrlLast_Name = Runner.getControl(pageid, 'Last_Name');
var ctrlName = Runner.getControl(pageid, 'Name');

function func() {
ctrlName.setValue(ctrlFirst_Name.getValue() +
(ctrlLast_Nme.getValue()));
};

ctrlFirst_Name.on('keyup', func);
ctrlLast_Name.on('keyup', func);

**********************************

Thanks!
Eric

RE: Combine First_Name and Last_Name into Name - Javascript

Actually your code looks like it is gonna work but still I wrote some basic code joining two names on keydown event. It is very basic code. Hope you will find useful.

HTML:

CODE --> HTML

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  FirstName:
  <input type="text" id="fname"><br/>
  LastName:
  <input type="text" id="lname"><br/>
  Full Name:
  <input type="text" id="fullname"> 
</body>
</html> 

JS:

CODE --> Javascript

function joinName(){
document.getElementById('fullname').value=
  document.getElementById('fname').value+" "+
  document.getElementById('lname').value;
}

document.getElementById('fname').addEventListener('keydown',joinName);
document.getElementById('lname').addEventListener('keydown',joinName); 

If you want to try out here is the link

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close