+ 3
[SOLVED] GetElementId Returning null
Please see the attached files from W3Schools for more information. Basically, I want to use a slider in a program on SoloLearn. I have correctly referenced the slider value according to the demo but document.getElementId("foo").value is returning TypeError null. I have the slider and script in separate files like the "split files" example. Why does the same code work in the "same files" example but not when they are split? https://code.sololearn.com/WiC21vtPL3lP/?ref=app https://code.sololearn.com/WA0zRlWMkjWG/?ref=app
6 Respuestas
+ 9
It because your javascript files run before HTML Get loaded.
Here is the code to fix that
window.onload = function(){
Your Codes Goes Here
}
https://code.sololearn.com/Wuo5n0yP2XND/?ref=app
+ 5
No problem!
+ 3
This question has been asked and answered many times before. So before posting new question make sure that the question has not been asked using the search bar.
Thanks! ☺
https://www.sololearn.com/discuss/1469777/?ref=app
https://www.sololearn.com/discuss/1143121/?ref=app
https://www.sololearn.com/discuss/68269/?ref=app
https://www.sololearn.com/discuss/769920/?ref=app
https://www.sololearn.com/discuss/1316935/?ref=app
+ 1
Huh.. hadn't thought of checking that. Thanks Jingga.
+ 1
I've got the same problem, thanks!
0
Seniru, I most definitely looked. I didn't realize that window.onload was the problem here.