I need to show an alert and stop the execution of the script when the user clicks the accept button when he does not select any week to pay, this is the ajax function:
$('#sub').click( function() {
$("#update").submit(function(e){
var formData = new FormData(this);
e.preventDefault();
$.ajax({
url: "files/hoursToPay.php",
type: "POST",
data: formData,
contentType: false,
cache: false,
processData: false,
success: function(data){
alert("Horas pagadas");
},
error: function(data){
console.log(data)
}
});
});
});
Inside the hoursToPay script:
<?php
// Si seleccionó al menos una semana
if (isset($_POST['hours'])):
//Codigo para pagar semanas
else:
echo '<script>alert("Selecciona al menos una semana");
return false;</script>';
endif;
?>
The problem is that the javascript code that is inside the script does not work, is there any way to make it work?, thanks.
In order to execute the alert with AJAX it is not necessary to call a PHP file, you can try
And why let the user click the button if the form is not properly filled out?
The solution I propose is very simple:
change
,paste
andkeyup
in that input: