Set the value of an input field

0
588

This is one way of doing it:

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

Another Solution

I use ‘setAttribute’ function:

<input type="text" id="example"> // Setup text field 
<script type="text/javascript"> 
  document.getElementById("example").setAttribute('value','My default value');
</script>

LEAVE A REPLY

Please enter your comment!
Please enter your name here