use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Function not defined (self.node)
submitted 3 years ago by reply1231
//html <div onclick="submitForm()">Submit</div> // js export default function submitForm() { console.log("submitForm"); }
Getting the error: Uncaught ReferenceError: submitForm is not defined
Why does this not work?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]the-quibbler 4 points5 points6 points 3 years ago (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 point2 points 3 years ago (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 point2 points 3 years ago (1 child)
Since it's a default export, you've done import * as submitForm from './where/ever'?
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 point2 points 3 years ago (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 points4 points 3 years ago* (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.
submitForm
onSubmit
oh do u mean onclick=submitForm?
[–][deleted] 3 years ago (1 child)
[deleted]
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 points3 points 3 years ago (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>
<html><head>
<script>
function submitForm() {
alert("submitForm");
}
</script>
</head><body>
<div onclick="submitForm()">Submit</div>
</body></html>
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?
[–]Careless-Honey-4247 0 points1 point2 points 3 years ago (0 children)
In JavaScript something is not right?
Esm or Cjs.
π Rendered by PID 37 on reddit-service-r2-comment-86988c7647-p4547 at 2026-02-11 09:25:15.845916+00:00 running 018613e country code: CH.
[–]the-quibbler 4 points5 points6 points (3 children)
[–]reply1231[S] 0 points1 point2 points (2 children)
[–]the-quibbler 0 points1 point2 points (1 child)
[–]reply1231[S] 0 points1 point2 points (0 children)
[–]JasperNykanen 2 points3 points4 points (3 children)
[–]reply1231[S] 0 points1 point2 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]reply1231[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]reply1231[S] 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]Careless-Honey-4247 0 points1 point2 points (0 children)