![]() |
|
[Javascript] Javascript DOM [object MouseEvent]undefined - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183) +---- Thread: [Javascript] Javascript DOM [object MouseEvent]undefined (/showthread.php?tid=6028455) |
Javascript DOM [object MouseEvent]undefined - blackcoder00 - Nov 27, 2019 i got this problem when i click the button [object MouseEvent]undefined PHP Code RE: Javascript DOM [object MouseEvent]undefined - MavenGradle - Nov 28, 2019 (Nov 27, 2019 09:14 PM)B2AD Wrote: To correct you, onclick requires a function name or function expression to be passed and it doesn't matter how many arguments you put in said function. You can even create a function that takes in no arguments.. However, onclick does pass on the MouseEvent to said function. You're right about the output though. https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onclick Also, OP the following variable is undefined as well in your code snippet, unless you're not posting everything: Code equWhat's more, OP, it's 2019 and you should declare your variables with scoping in mind (e.g. let and const). RE: Javascript DOM [object MouseEvent]undefined - MavenGradle - Nov 28, 2019 (Nov 28, 2019 07:19 PM)B2AD Wrote: Can you give an example of what you're referring to? The link you provided there outlines my understanding of it: OP posted an example for you above that confirms this and obviously you wouldn't be able to use any extra parameters in said case, hence they are undefined as you stated out. But none-the-less it is not impossible to do so. As referenced by the JavaScript specs. Regardless, you can very well share a function with other methods other than the onclick handler of an element, hence the usage of passing a method name and by sharing some functionality inside said method, which is Object-Oriented programming related. |