I am trying to activate a javascript function when I click on the form submit button
Without it redirection to another page. I dont know if that is possible?
You have an extra quote in your first line there, before onsubmit, but it seems to work regarless.
I haven’t used the onsubmit attribute, but it seems to have that built in. I usually just create my one submit button so I can handle it the way I want.
Sorry if that’s not great information.
I did notice a few other things - you have a habit of using PascalCase for your variables. I JS you should only do that for classes and object constructors. There are some other cases, but not in vanilla JS.
Also in this:
.catch(error => error('unable to add product', error));
onsubmit takes a script it can execute, so it needs to be valid JS (in this case, needs to call a function).return CreateProduct() is not that, it’s not valid JS.
Also, for future reference, I would strongly suggest using addEventHandler in your JS, don’t use HTML attributes like onsubmit, so eg
What page is it redirecting to, you haven’t specified an action attribute on your form?
The first thing you normally do when you don’t want the default “browser loads new page” behaviour is calling event.preventDefault() at the very top of your submit handler.