I am just beginning with programming and starting with javascript. I am not able to get a form filled in html and get it into javascript by getElementById. Could you please take a look at my code and tell me a solution.
HTML form
input type="text" id="myText"
input type="submit" id="submit"
javascript
var x = document.getElementById("myText").value;
console.log(x);
If you put some value into you input field it should work. Please check the example (https://codepen.io/alekskorovin/pen/abLOzBw):
var x = document.getElementById("myText").value; console.log(x);
<input type="text" id="myText" value="test" />
Of course if you want dynamic value in the input - you have to make it empty and then add some event handler, inside that handler use that code var x = document.getElementById("myText").value; console.log(x);