I have been trying my hands on javascript and it works but suddenly has stopped working ie js functions are not getting called. I have placed both .js and html file on desktop but still not working.
Error:
Uncaught ReferenceError: funcLoadImage is not defined
at HTMLButtonElement.onclick
and this error could be for any function i am calling.
JS:
function funcLoadImage() {
document.getElementById("img1").src = "https://upload.wikimedia.org/wikipedia/commons/3/36/Hopetoun_falls.jpg"
}
function funcMath(type, data) {
if (type == 1) {
document.getElementById("img1").alt = 'Type 1'
}
if (type == 2) {
document.getElementById("img1").alt = 'Type 2'
}
}
funtion funcDate() {
document.getElementById("img1").alt = 'date add'
}
Html Code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img id="img1" src="" alt="No image loaded" width="50%" height="50%"/>
<button id="btn1" width="20%" height="20%" onclick='funcLoadImage()'>Load Image</button>
<button id="btn2" width="20%" height="20%" onmouseover="this.style.width='60%'" onmouseout="this.style.width='20%'">Write Doc</button>
<button id="btn3" width="20%" height="20%" onclick='funcMath(1,4)'>Calculate</button>
<button id="btn4" width="20%" height="20%" onclick='this.innerHTML=Date()'>Display Date</button>
<p>
</p>
<script src="script1.js"></script>
</body>
</html>
Try this.............
function funcLoadImage() { document.getElementById("img1").src = "https://upload.wikimedia.org/wikipedia/commons/3/36/Hopetoun_falls.jpg"; } function funcMath(type, data) { if (type == 1) { document.getElementById("img1").alt = 'Type 1'; } if (type == 2) { document.getElementById("img1").alt = 'Type 2'; } } function funcDate() { document.getElementById("img1").alt = 'date add'; }
<!DOCTYPE html> <html> <head> </head> <body> <img id="img1" src="" alt="No image loaded" width="50%" height="50%"/> <button id="btn1" width="20%" height="20%" onclick='funcLoadImage()'>Load Image</button> <button id="btn2" width="20%" height="20%" onmouseover="this.style.width='60%'" onmouseout="this.style.width='20%'">Write Doc</button> <button id="btn3" width="20%" height="20%" onclick='funcMath(1,4)'>Calculate</button> <button id="btn4" width="20%" height="20%" onclick='this.innerHTML=Date()'>Display Date</button> <p> </p> <script type="text/javascript" src="script1.js"></script> </body> </html>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.