Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!