Hi, I cannot call a function with onclick() and would appreciate any help.
The js file itself is in a sub-folder (not at the bottom of the html page).
One of those is to call a javascript function from a button.
The javascript file is in an js-folder, which is in an asset folder.
I get the error:
(index):55 Uncaught ReferenceError: fillForm is not defined
at HTMLButtonElement.onclick ((index):55)
Please note that there are other functions on the js page, but I copied the only one that is problematic. All other functions were working as expected.
Thank you in advance.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="shortcut icon" href="">
<title>JavaScript</title>
<link rel="stylesheet" href="assets/styles/index.css">
<script type="module" src="assets/js/exercise-5.js"></script>
</head>
<body>
<h1>This is my page</h1>
<!-- irrelevant code omitted
-->
<input id="oneInput">
<button type="button" onclick="fillForm()">Submit</button>
<p id="comment"></p>
</body>
</html>
addEventListener('load', main);
function main(){
removeEventListener('load', main);
}
export function fillForm(){
let x = document.getElementById("oneInput").value;
let text = "";
if (isNaN(x) || x < 1 || x > 10) {
text = "Input not valid";
} else {
text = "Input OK";
}
document.getElementsByClassName("comment").innerHTML = text;
}