This is my button element:
<button id="loginButton"
...
onclick="e.preventDefault(); return true;"/>
But this approach gives me after login button click error in console:
Uncaught ReferenceError:
e
is not defined
Do you know how to fix my button to avoid "e
is not defined" error in console?
This is my button element:
<button id="loginButton"
...
onclick="e.preventDefault(); return true;"/>
But this approach gives me after login button click error in console:
Uncaught ReferenceError:
e
is not defined
Do you know how to fix my button to avoid "e
is not defined" error in console?
-
2
try to use
event
instead ofe
– AterLux Commented Oct 26, 2020 at 12:10 - with event instead of e - i cannot log to application, nothing happens after 'login' click – mtmx Commented Oct 26, 2020 at 12:25
- why something should happens? The script only prevents default action and do nothing. So, when nothing happens - it works as intended. – AterLux Commented Oct 26, 2020 at 12:41
- But i cannot login into application if i change e -> event – mtmx Commented Oct 26, 2020 at 12:43
-
1
yes, because
event.preventDefault();
prevents default action (submitting the form or whatever it is) of the event. I.e. it starts working. Your question is not about logging in. It is about Uncaught ReferenceError – AterLux Commented Oct 26, 2020 at 12:45
2 Answers
Reset to default 3in events (like onclick="..."
) you can specify either a function name, then this function has to have a single parameter, where the event object will be passed.
Or you can specify an JavaScript expression (as in your case), in this case there will be created implicit function (event) { ... }
with your code placed inside.
I.e. in that case you have to use event
(instead of e
) as the name of the event object.
e
is a variable monly used in event handlers. However you never defined e
in your code. I remend using an event listener in JS.
document.getElementById('loginButton').addEventListener('click', function(e) {
e.preventDefault();
return true;
});
This will acplish what you need.