Friendship … is born at the moment when one man says to another “What! You too? I thought that no one but myself . . .

— C.S. Lewis, The Four Loves

Set the value of an input field using JavaScript

This is one way of doing it:

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

use ‘setAttribute’ function:

<input type="text" id="example"> // Setup text field 
<script type="text/javascript"> 
  document.getElementById("example").setAttribute('value','My default value');
</script>
What’s your Reaction?
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

Leave a Reply