Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active July 5, 2020 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/ac5ceeafe70e9fa30aba8a347e26e681 to your computer and use it in GitHub Desktop.
Save parzibyte/ac5ceeafe70e9fa30aba8a347e26e681 to your computer and use it in GitHub Desktop.
document.addEventListener("DOMContentLoaded", () => {
const $select = document.querySelector("#id_cliente");
let lastSelectedIndex = $select.selectedIndex;
$select.addEventListener("click", function () {
lastSelectedIndex = $select.selectedIndex;
});
$select.addEventListener("change", function (e) {
if (!confirm("Al cambiar de cliente se eliminará la lista de artículos. ¿Continuar?")) {
$select.selectedIndex = lastSelectedIndex;
return;
}
// Aquí el usuario sí ha aceptado, continúa con lo que harías normalmente
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment