Let’s see if someone could help me solve this problem that I don’t understand.
I’ve been looking to solve a problem for a couple of days, I have a confirmation alertify function.
With an html form I call the alertify function with the onclick event, but in the chrome dev tools it appears that submit is not a function. The Id of the form matches the javascript function and with a console.log the DOM identifies the form correctly.
html form
<form name="formulario" id="edit-form" method="POST" action="#" enctype="multipart/form-data">
<input class="button" type="submit" name="submit" id="submit" onclick="return showAlertConfirm('¿Está seguro de que desea editar el registro?','edit-form',url)" value="Editar" />
javascript function
//Funcione alertify para editar/eliminar registro
function showAlertConfirm(message,formId,url) {
// Prevent the default form submission
document.getElementById(formId).addEventListener("submit", function (event) {
event.preventDefault();
});
// Display the confirmation dialog
alertify.confirm(
"ATENCIÓN",
message,
function () {
console.log("ok clicked");
console.log(formId);
console.log(document.getElementById(formId));
let formObj = document.getElementById(formId);
formObj.submit();
},
function () {
console.log("Cancel clicked");
setTimeout(function() {
showNotification("Operación Cancelada");
// Después de 5 segundos, redirige
setTimeout(function() {
window.location.href = url;
}, 5000);
}, 0); // Espera 5 segundos antes de mostrar la notificación
}
);
// Always return false to prevent the default form submission
return false;
}
Error
jscript.js:212 Uncaught TypeError: formObj.submit is not a function
at Object.<anonymous> (jscript.js:212:15)
at Object.callback (alertify.min.js:3:2247)
at U (alertify.min.js:2:13068)
at Object.V (alertify.min.js:2:13159)
at HTMLDivElement.<anonymous> (alertify.min.js:2:1267)