Uncaught TypeError: Cannot read property 'value' of null Line: 1 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Uncaught TypeError: Cannot read property 'value' of null Line: 1

<html> <head> <title>Page Title</title> </head> <body> <input type="text" name ="arguments" value="[[1,2,3,4],[1,2,3]]" id="aaa"/> <input type="button" value="Get Symmetric Diff" onClick="sym()" /> </body> </html> JS: var userInput = document.getElementById('aaa').value; function sym() { alert(userInput); }

31st Dec 2016, 3:20 PM
ONLY JS PLEASE!
ONLY JS PLEASE! - avatar
4 Answers
+ 2
Where is the script tag included here? It looks to me like the script is running before the document has finished loading. For best results you should include your script at the very end of the body tag.
31st Dec 2016, 3:26 PM
James Durand
James Durand - avatar
+ 2
Probably the best thing to do is more the assignment into the sym function.
31st Dec 2016, 3:30 PM
James Durand
James Durand - avatar
+ 1
sorry i didnt say, i was using sololearn code playground, i dont need to include
31st Dec 2016, 3:29 PM
ONLY JS PLEASE!
ONLY JS PLEASE! - avatar
0
Thanks James, that solved my problem
31st Dec 2016, 3:33 PM
ONLY JS PLEASE!
ONLY JS PLEASE! - avatar