Home > Net >  Not able to get form data using getelementbyId from Html to JS
Not able to get form data using getelementbyId from Html to JS

Time:12-02

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);

CodePudding user response:

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" />
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related