0

Uncaught TypeError: Cannot read property 'value' of null

Why am I getting this error and is the code alright https://code.sololearn.com/WU8iysLOnqDj/?ref=app

18th Jun 2020, 5:51 PM
kaustubh patil
kaustubh patil - avatar
4 Antworten
+ 4
Where to start? This is your code as it stands. alert ("welcome") var a=document.getElementById("t1").value // You have no element with id "t1". Change this to "t" var b=document.getElementById("t2").value; // You have no element with id "t2". Change this to "f" var x=parseInt(a) var y=parseInt(b) document.getElementById("b1").addEventListner("click",fl) // addEventListner should be addEventListener, fl should be f1. function f1() { var c= x+y document.getElementById("p1").innerHTML= "The addittion is " +c } I have added comments to show you changes that need to be made. Once these are changed, you have the problem that the code only takes the values of both input boxes as soon as the code is run, not when the button is clicked. I suggest you move the four statements starting with var a, var b, var x and var y inside the f1 function. This should really all be put into window.onload = function() {...} too.
18th Jun 2020, 7:18 PM
Russ
Russ - avatar
+ 1
In your HTML, change the button input attribute onclick from "f1" to "f1()"
19th Jun 2020, 4:22 PM
Russ
Russ - avatar
0
Russ thanks a lot for helping me out I had really made some silly mistakes I did all above mentioned changes but then to I am not getting desired output The function f1() is not working properly Can you please se to code once again Thanking you in anticipation
19th Jun 2020, 4:18 PM
kaustubh patil
kaustubh patil - avatar
0
Russ Thanks a lotttt it worked properly I'll practise more often and improve my small mistakes
12th Jul 2020, 3:14 PM
kaustubh patil
kaustubh patil - avatar