Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
Is it possible to give a submit input button the onsubmit attribute with javascript?

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())
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

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);
about 4 years ago · Juan Pablo Isaza Relatório

0

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.

onSubmit event on a button element will it work?

about 4 years ago · Juan Pablo Isaza Relatório

0

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.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda