I want to validate a form with js through an alert
My code is the following but it is not working for me
I have removed the type="submit" from the button, otherwise, it always confirms the form
function security(){
var mensaje = confirm("¿Estás seguro de que quieres BORRAR este aviso?");
if (mensaje) {
var theForm = document.forms['formborrar'];
theForm.submit();
}
else {
}
}
<form action="borrar.php" method="post" name="formborrar">
<input type="text" name="id" value="<?php echo $id; ?>" style="display: none;">
<input class="btn" onclick="security()" type="submit" value="Borrar Aviso" name="submit">
</form>