javascripthtmlformsinputhtml-input

Set the default value of an input field


How would you set the default value of a form <input> text field in JavaScript?


Solution

  • This is one way of doing it:

    document.getElementById("nameofid").value = "My value";