Hello I've tried several things to give my submit button the onsubmit attribute. But I can't figure out, how to set onsubmit. Maybe you have an idea.
let btn = document.createElement('input');
btn.value = "Delete";
btn.name = "deleteButton";
btn.type = "submit";
btn.onsubmit="deleteCell();
let btn = document.createElement('input');
btn.value = "Delete";
btn.name = "deleteButton";
btn.type = "button";
btn.addEventListener('submit', deleteCell())
The "submit" event is for a form, not an input. You can use the "click" event on the input though:
const deleteCell = () => {
console.log("hello World!")
};
let btn = document.createElement('input');
btn.value = "Delete";
btn.name = "deleteButton";
btn.type = "button";
btn.addEventListener('click', deleteCell);
A button does not have a onSubmit or submit event.
onSubmit is a property of a <form> element.
With button, you should use btn.onClick = deleteCell or addEventListener('click',deleteCell)
Have a look here for more details on a similar question.
What exactly are you trying to achieve? Usually a submit button is wrapped inside a <form> tag. The form might have a onSubmit attribute or an action and a method. A button can have the onClick attribute to run a specific function.