Function not found on onclick

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">

    <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="">
    <link rel="stylesheet" href="assets/styles/index.css">
    <script type="module" src="assets/js/exercise-5.js"></script>


    <h1>This is my page</h1>
<!-- irrelevant code omitted
        <input id="oneInput">
        <button type="button" onclick="fillForm()">Submit</button>
        <p id="comment"></p>


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;

Your exercise is about using module code, which requires a server, even a local server, and cannot work without there being a server of some kind involved.

Where did you get the exercise information from? They should also provide instructions on how to set up a suitable server for what they’re teaching.

Thank you for your reply.
I do have a server (live-server). We solved the issue by replacing

    <script type="module" ...


<script type="text/javascript" ...

At the top of the html file. The teacher says to put an eventListener in the JS instead.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.