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/
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With