+ 1
Pls help
Cannot read properties of null as (' .value ') Function () { Let valueid = Document.getElementById('exampleid').value; Console.log('valueId') }
8 Réponses
+ 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
+ 1
What are you attempting to do? Please provide an explanation and show your full code.
+ 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 = ' ';
}
}
+ 1
Well that code does not appear to throw the same error :D
+ 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);
+ 1
even i tried changing my code's still says
Cannot read properties of null (reading ' value ')
+ 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.
+ 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