Cannot set property InnerHTML of null !!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Cannot set property InnerHTML of null !!!

Keep getting this error and looked it up online. Most people say to use window.onload but when I look at the examples in the Sololearn tutorials and other people's code they do the same thing without using it. Would love to have someone explain this to me. The program is suppose to input user name and assign a random jersey number. It works using the document.write method commented out but I also want to make the name fit the jersey regardless of the size of their name which is why I need it in the div tags. https://code.sololearn.com/Wu6rIHv66A4m/?ref=app

1st May 2020, 11:08 PM
DAYLINER BAND
DAYLINER BAND - avatar
2 Answers
+ 1
Wrap your JS code in window.onload = function () { ... code here... }; Also, you need to change one to get the I'd of number. They are both set to lastname.
1st May 2020, 11:46 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Thanks so much ChaoticDawg. It works now. Is this a pretty standard thing you have to do or and I writing this code poorly?
2nd May 2020, 1:12 AM
DAYLINER BAND
DAYLINER BAND - avatar