Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display first and lastname with JavaScript

I'm learning JavaScript and I'm trying to make it so the user is able to enter a name and lastname and then click a send button. When that happens the name and lastname is displayed on the the screen just bellow.

The problem is that it doesn't work. Nothing happens when the user clicks the send button.

Here is how I tired it.

HTML:

    <body>
First name:<br>
<input type="text" name="firstname">
<br>
Last name:<br>
<input type="text" name="lastname">
<br>
<input type="button" value="Send" onclick="MyFunction()">
    <div id="here"></div>    

<body>

JavaScript:

function MyFunction() {
    var first, second;
    first = document.getElementById("firstname").value;
    second = document.getElementById("lastname").value;

    document.GetElementById("here").InnerHTML = first;
    document.GetElementById("here").InnerHTML = second;
}

https://jsfiddle.net/7wu3gjqm/

like image 599
John.P Avatar asked Dec 02 '25 22:12

John.P


1 Answers

This is your example worked fine after some changes :

HTML:

<input type="text" name="firstname" id="firstname">
<input type="text" name="lastname" id="lastname">

JS:

myFunction = function() {
    var first = document.getElementById("firstname").value;
    var second = document.getElementById("lastname").value;

    document.getElementById("here").innerHTML = first+" "+second;
}

Find your example here : jsFiddle.

like image 157
Zakaria Acharki Avatar answered Dec 04 '25 14:12

Zakaria Acharki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!