Set the value of an input field

SebastianOpperman picture SebastianOpperman · Sep 30, 2011 · Viewed 1.4M times · Source

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

Answer

James picture James · Sep 30, 2011

This is one way of doing it:

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