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

69
Views
Alerta antes de ejecutar valor en select

Tengo un tipo de entrada Seleccionar con 3 opciones y quiero mostrar una ventana de Alerta cuando se selecciona cualquier opción.

Esta alerta tiene que poner en espera la ejecución de la opción seleccionada y dar una advertencia como: "Los cambios no guardados se perderán. ¿Está seguro de que desea continuar?", entonces quiero la opción de 'Cancelar' la ejecución o presionar 'Aceptar' y ejecutar.

¿Cómo puedo agregar una opción Cancelar dentro de la alerta para que no ejecute la opción seleccionada y permanezca en la opción seleccionada anteriormente?

Ver mi código a continuación y en el JSFiddle

HTML:

 <p> Choose your formation: </p> <select id="formation" name="formation" onchange="myFunction(formation)"> <option value="1"> 1-1-2 </option> <option value="2"> 1-2-1 </option> <option value="3"> 2-1-1 </option> </select> <p> You chose the following formation: <spam id="demo"> X</spam>. </p>

JavaScript:

 function myFunction(formation) { alert("Unsaved changes will be lost. Are you sure you want to continue?") if(document.getElementById('formation').value == "1") { document.getElementById("demo").innerHTML = "1-1-2"; } if(document.getElementById('formation').value == "2") { document.getElementById("demo").innerHTML = "1-2-1"; } if(document.getElementById('formation').value == "3") { document.getElementById("demo").innerHTML = "2-1-1"; } }
about 4 years ago · Juan Pablo Isaza
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!