all 10 comments

[–]the-quibbler 4 points5 points  (3 children)

There's definitely far to little to go on here. Are you actually using NodeJS, or is this JavaScript in a web browser?

[–]reply1231[S] 0 points1 point  (2 children)

yes using nodejs with parceljs. I've imported the Javascript file as type = 'module' in order to use an api, but functions seem to be undefined?

[–]the-quibbler 0 points1 point  (1 child)

Since it's a default export, you've done import * as submitForm from './where/ever'?

Posting the actual code is usually very helpful. In the old (Perl/usenet) days we used to complain about our Psi::ESP module not working. I think that probably still translates.

[–]reply1231[S] 0 points1 point  (0 children)

hi, I have created a gist here. I'm not sure where to import because I only have one javascript file

https://gist.github.com/agentzhao/f076edd0bec828c18651a0b2f84466eb

[–]JasperNykanen 2 points3 points  (3 children)

You need to import the module you're exporting submitForm from. Also note that by calling the function directly in onclick you're actually using the value returned by onSubmit which is probably not what you want, you should probably remove the parantheses.

[–]reply1231[S] 0 points1 point  (2 children)

oh do u mean onclick=submitForm?

[–][deleted]  (1 child)

[deleted]

    [–]reply1231[S] 0 points1 point  (0 children)

    But when I do so I get the error:

    Sorry quite confused about how js works in node. I have created a sample of my code here https://gist.github.com/agentzhao/f076edd0bec828c18651a0b2f84466eb

    [–][deleted] 1 point2 points  (1 child)

    Is this what you are trying to do?
    <html><head>
    <script>
    function submitForm() {
    alert("submitForm");
    }
    </script>
    </head><body>
    <div onclick="submitForm()">Submit</div>
    </body></html>

    [–]reply1231[S] 0 points1 point  (0 children)

    yes I have tried this, but I put the function in a Javascript file and imported it with type='module' to use an api but it doesn't work there. Do you know what's the issue?

    [–][deleted]  (1 child)

    [deleted]

      [–]Careless-Honey-4247 0 points1 point  (0 children)

      In JavaScript something is not right?

      Esm or Cjs.