Why doesnā€™t var x = input.value work sometimes? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Why doesnā€™t var x = input.value work sometimes?

Iā€™ve tried using var x = document.getElementById(ā€œinputā€).value; before and it didnā€™t really work. I never used it since then. I just used input.value instead of var x = input.value; Iā€™ve tried using the the var x... method today, it didnā€™t work as expected. I donā€™t really have a specific code right now, but y doesnā€™t it work?

19th Dec 2019, 3:02 AM
Ginfio
Ginfio - avatar
1 Resposta
0
Try to console.log(input) See to it that it is a valid DOM element you can use, e.g. it is not undefined, and you don't get an error message in console. Run the test in window.onload event handler to ensure the element is rendered beforehand.
19th Dec 2019, 5:55 AM
Ipang