+ 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

18th Dec 2018, 1:11 AM
Nic Robichaud
Nic Robichaud - avatar
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
18th Dec 2018, 1:15 AM
Jingga Sona
Jingga Sona - avatar
+ 5
No problem!
18th Dec 2018, 1:40 AM
Jingga Sona
Jingga Sona - avatar
+ 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
18th Dec 2018, 1:03 PM
Seniru
Seniru - avatar
+ 1
Huh.. hadn't thought of checking that. Thanks Jingga.
18th Dec 2018, 1:34 AM
Nic Robichaud
Nic Robichaud - avatar
+ 1
I've got the same problem, thanks!
18th Dec 2018, 11:52 AM
Dr.Hippo
Dr.Hippo - avatar
0
Seniru, I most definitely looked. I didn't realize that window.onload was the problem here.
18th Dec 2018, 5:20 PM
Nic Robichaud
Nic Robichaud - avatar