How to print an input in javascript

please i need a hepl to print the input text

        <p id="printhere"></p>
         Name : <input type="text" id="userName"> 
        <button  onclick="display()">Add Info</button>

function display(){

//Assigning the variable to the user input
	var userName = document.getElementById("userName").value;

// to print the input here
document.getElementById("printhere").innerHTML = userName;

i ran your code here:,js,output

and it ran fine

but that’s amazingly

have been running the same thing on jsfiddle and it never worked

It might be a jsfiddle problem. I got this error in my console when running it on js fiddle. Running the code on jsbin ran fine

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.