Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combine First_Name and Last_Name into Name - Javascript

Status
Not open for further replies.

EEM6498

Technical User
Jan 15, 2021
1
US
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
 
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:

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:

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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top