<div class="form-group col-3">
<div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
<input type="checkbox" class="custom-control-input" name="abonnement_apres_essai" id="abonnement_apres_essai" onclick="myFunction()">
<label class="custom-control-label" for="abonnement_apres_essai">Abonnement après essai</label>
</div>
</div>
<script>
window.onload = function myFunction() {
const val1 = 1;
const val2 = 0;
var abonnementapresessai = document.getElementById("abonnement_apres_essai");
var afficher_menu_abonnment = document.getElementById("afficher_menu_abonnement");
if (abonnementapresessai.checked == true) {
afficher_menu_abonnement.style.display = "block";
document.getElementById("abonnement_apres_essai").value = val1;
} else if (abonnementapresessai.checked == false) {
afficher_menu_abonnement.style.display = "none";
document.getElementById("abonnement_apres_essai").value = val2;
}
}
</script>
Hi guys,
When running the checkbox (toggle switch) is enabled the returned value is 1 is saved in the database,
On the other hand, if the checkbox is deactivated, the value is null and not the value 0 and displays an error in MySQL.
The objective is to return a value 1 or 0 during the checkbox, by default the checkbox is deactivated the returned value 0,and the checkbox is enabled the return value 1
Anyone have any solutions for this problem?
Thanks,
Thanks for your feedback,
I used the controller function for database:
And i use a route with the POST method