... ... ...

How to use event.preventDefault() on form submit as 'event' in javascript are now deprecated?

56 views Asked by At

I am getting a warning for my below code saying that 'event' in javascript have been deprecated.

HTML

<form onsubmit="handleFormSubmit(event)">
   ...
</form>

JS

function handleFormSubmit(event){
   event.preventDefault();
}

I tried removing the 'event' from the attribute value. But this gives an error saying "event not defined".

HTML

<form onsubmit="handleFormSubmit()">
   ...
</form>

JS

function handleFormSubmit(event){
   event.preventDefault();
}

I also tried the addEventListener() method and it does work as expected. But I am looking for a way to assign the function using inline attribute.

0

There are 0 answers