html - Display first and lastname with JavaScript -


i'm learning javascript , i'm trying make user able enter name , lastname , click send button. when happens name , lastname displayed on the screen bellow.

the problem doesn't work. nothing happens when user clicks send button.

here how 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 example worked fine after 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 example here : jsfiddle.


Comments