Concatenate two strings in HTML

The following HTML code uses javascript to concatenate two strings on the client side.

First name:<input type=”text” id=”firstname”><br>
Second name:<input type=”text” id=”secondname”><br>
<input type=”button” id=”addbutton” value=”concate” onClick=”addTwoStrings()”>
function addTwoStrings()
var f1=document.getElementById(“firstname”).value;
var f2=document.getElementById(“secondname”).value;
var result=f1+f2;

Tags used

<input type>:
By default input type is text but we can choose from a wide range of options like button, checkbox, color, date, email, file, etc.

type=”button” will be triggered when you click on it and will perform the addTwoStrings() function.

id=”addButton” is the identifier of the button
input value=”concate” the value which will be displayed on that button.

onClick is the event that will execute javascript code.

addTwoString() will return the concatenated string.

also see

C Programming language
Go Programming language
Linked List Array
Simplification Queue
DBMS Reasoning
Aptitude HTML
Previous articleMerge and Sort two Linked list in C
Next articleArrange data in alphabetical order in C


Please enter your comment!
Please enter your name here