Form submit button not having click event in browser, yet form is getting submitted?

Both on right click and left click? And only when submit button is clicked, nowhere around the form. Any explanation for it? Can you just submit form without Click event?
10 Replies
MarkBoots
MarkBoots2y ago
if the button is of type="sumbit", then yes, it will try to send the form
Dovah
DovahOP2y ago
It is. So? It reacts on click but it has no event listener? Liek a native built in HTML listener?
MarkBoots
MarkBoots2y ago
that is native behaviour yes. it will try to do the action that is set in the form element if you dont want that, create and event listener on formsubmit or button click, and do event.preventDefault
Dovah
DovahOP2y ago
So I was testing automation on a random website, and put button.click() but it did not work, or I did something wrong? IS my code right?
MarkBoots
MarkBoots2y ago
button.click() is nothing button.onClick(()=>{...}), or button.addEventListener("click", ()=> { ...} )
Dovah
DovahOP2y ago
I was automating my code to click it, like you would with mouse. Is it still wrong? Hence the button.click();
MarkBoots
MarkBoots2y ago
no, that won't work like that. you'll have to simulate a mouse click with a dispatch event in order to do that ( I think, never tried)
MarkBoots
MarkBoots2y ago
Medium
How to Simulate a Mouse Click Using JavaScript
We can trigger a mouse click event by using the MouseEvent constructor.
Dovah
DovahOP2y ago
Oh okay! Will read through it tomorrow and see how it goes! Thanks a lot!
MarkBoots
MarkBoots2y ago
good luck
Want results from more Discord servers?
Add your server