Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

387
Vistas
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 Respuestas
Responde la pregunta

0

just use type="button":

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

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda