I have created a php form with multiple checkboxes and there is a script that controls if the sum (sum of all checkboxes values) is greater than a specific number.If yes, a sweetalert box appears.The problem is that when I click the 'OK' button on the sweetalert I want to remove the last checked attribute and to remove that value from the sum to execute the script again and display the right results.I cannot figure this out..Any ideas will be helpful!
Script :
var sum = 0;
var maxSum = <?php echo $form_points; ?> ;
$('[name="opt"]').change(function(){
if($(this).is(":checked")) {
sum = sum + parseInt($(this).val());
}
else
{
sum = sum - parseInt($(this).val());
}
if( sum > maxSum )
{
//$('#checkbox').prop('checked',prop);
sweetAlert("ΠΡΟΣΟΧΗ", "Υπερβήκατε τους πόντους του πελάτη", "error"); //your alert message
$("#checkbox").click();
}
})
For example : If the specific number is 500 and the sum is 550(1st checkbox value=200 + 2nd checkbox value=200 + 3rd checkbox value=150) and after I click on 'OK' then the script must removes the 3rd checkbox value from the sum (so sum must be now 400) and unchecks the the checkbox..
Aucun commentaire:
Enregistrer un commentaire