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

379
Views
How to add a second button to the react form that not execute the first button handler function?

I have an React form. This form have a button. This is the submit button. If i click this button execute the first function (submitHandler)which pointer is on the form.

I want add a second button to the form the "back button". This button should execute an other function but not the first function

Both button should be on the same form

Form.js

import React, { useState } from "react";
import "./Form.css";

const Form = (props) => {
  const submitHandler = (event) => {
    event.preventDefault();
    console.log('Some console log now from Submit Hanlder')
  };

  const secondFunction = event =>{
  
    console.log('Some other console log')
  }

  return (
    <form onSubmit={submitHandler}>
      <div className="new-expense__controls">
        <div className="new-expense__control">
          <label>Title</label>
          <input type="text" />
        </div>
        <div className="new-expense__control">
          <label>Amount</label>
          <input type="number" />
        </div>
        <div className="new-expense__control">
          <label>Date</label>
          <input type="date" />
        </div>
        <div className="new-expense__actions">
          <button type="submit">Submitting</button>
          <buton>Second button....</buton>
        </div>
      </div>
    </form>
  );
};

export default Form;
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

just use type="button":

<button type="button">Second button....</button>
about 4 years ago · Juan Pablo Isaza Report

0

You can add a onClick event to the second button to execute the secondFunction:

<button onClick={() => secondFunction()}>Second button....</button>

Note: the onClick event in reactjs is with a Capital letter C.

const secondFunction = event => {
    event.preventDefault();
    console.log('Some other console log')
}
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!