+ 1

Pls help

Cannot read properties of null as (' .value ') Function () { Let valueid = Document.getElementById('exampleid').value; Console.log('valueId') }

12th May 2022, 3:34 AM
Fami-Coder
Fami-Coder - avatar
8 odpowiedzi
+ 2
Chris Coder Bob_Li oh my, i just typed the none existing id and when i typed the existing one, it worked the problem is just the id i typed not exist
12th May 2022, 5:50 AM
Fami-Coder
Fami-Coder - avatar
+ 1
What are you attempting to do? Please provide an explanation and show your full code.
12th May 2022, 4:14 AM
Chris Coder
Chris Coder - avatar
+ 1
Chris Coder im trying to make an working calculator. Here's the code. function calculator(number) { document.getElementById('result').value+=number; } function enterResult() { let result = document.getElementById('result'); let calculate = eval(result); document.getElementById('result').value = calculate; function clear() { document.getElementById('result').value = ' '; } }
12th May 2022, 4:38 AM
Fami-Coder
Fami-Coder - avatar
+ 1
Well that code does not appear to throw the same error :D
12th May 2022, 5:00 AM
Chris Coder
Chris Coder - avatar
+ 1
you could simplify it a bit. the get DOM element part is repeated multiple times, and the function name calculator is not really doing the calculating. const output = document.getElementById('result'); function display(number) { output.value = number; } function calculate(input) { let result = eval(input); display(result); } function clear() { display('') } calculate(5+5*2/4); setTimeout(()=>{clear()},2000);
12th May 2022, 5:08 AM
Bob_Li
Bob_Li - avatar
+ 1
even i tried changing my code's still says Cannot read properties of null (reading ' value ')
12th May 2022, 5:34 AM
Fami-Coder
Fami-Coder - avatar
+ 1
Fami-Coder it happens to all of us. error messages can be tricky. But after a while, you get a good feel of what they mean and find the bug.
12th May 2022, 6:00 AM
Bob_Li
Bob_Li - avatar
+ 1
I also had this problem a long time ago, but it was fixed with a trick I have to remind you that the browser executes the codes from top to bottom, not from bottom to top In SoloLearn, JS codes are executed first, then CSS and then HTML To solve this problem, write the codes after the tag is created You can put JavaScript codes in the script tag Another way is to write codes in window.onload function But it is better if you write the script tag after creating the tag
9th Oct 2022, 1:49 AM
aliz6398suisiTerminatorEmpireBot
aliz6398suisiTerminatorEmpireBot - avatar