+ 2

Why this code is not working here...? Can anyone help..!

https://code.sololearn.com/W6DmtLe6574u/?ref=app

11th Jun 2018, 9:50 AM
Sachin Bhatt
Sachin Bhatt - avatar
5 Answers
+ 8
It's because your code in JS section loads before your html; delay it with onload or similar event it should work fine. this.onload = function(){ //your JS code here... }
11th Jun 2018, 10:08 AM
Lord Krishna
Lord Krishna - avatar
11th Jun 2018, 10:13 AM
Jonathan Pizarra
Jonathan Pizarra - avatar
+ 2
//Fix your errors. Try this in js //on clicking button action window.onload = function() { function calculateAmount() { // storing the data var income = document.getElementById("income").value; var interest = document.getElementById("interest").value; var years = document.getElementById("years").value; //validation if(income === "" || interest === "") { window.alert("Please Enter a Valid Input!"); return; } if(years === "" || years <= 1) { years = 1; } var fAmount = (income * 12 * interest * years) / 100; //display document.getElementById("totalinterest").style.display = "block"; document.getElementById("amount").innerHTML = fAmount; //hide amound and returns // document.getElementById("totalinterest").style.display = "none"; } document.getElementById("calculate").onclick = calculateAmount; };
11th Jun 2018, 10:17 AM
Gopal Gautam
Gopal Gautam - avatar
0
thankyou all for answering 🙂
11th Jun 2018, 10:24 AM
Sachin Bhatt
Sachin Bhatt - avatar
0
now it's working ☺️
11th Jun 2018, 10:33 AM
Sachin Bhatt
Sachin Bhatt - avatar