Search code examples
javascripthtmldomgetelementbyid

Get the Value from Prompt in the input text


I want the value user enter in the Prompt shows in the input text field id="myName"

var a = prompt("Enter your name");
document.getElementById("myName").innerHTML.value = a;
<input type="text" id="myName">


Solution

  • Don't use innerHTML here, just change the property value.

    var a = prompt("Enter your name");
    document.getElementById("myName").value = a;
    <input type="text" id="myName">