I have a modal form and an input field with checkbox type. I want to create an update form, so I should request data from php and passing to html. So I have two conditions, if parameter = 0 attribute checked="checked", else attribute checked become unchecked. So I use jQuery, this is my code:
<input class="form-check-input" type="checkbox" value="Ya" name="agenda_pimpinan" id="tampilkan_agenda_pimpinan" checked="checked"/>
<script type="text/javascript">
var x = event.tampilkan_agenda_pimpinan;
console.log(x);
if(x != 0) {
$('#tampilkan_agenda_pimpinan').removeAttr("checked");
}
else {
$('#tampilkan_agenda_pimpinan').attr("checked");
}
</script>
Assume I have two data that I want to update, we assume the names data1 and data2. Data1 have parameter = 0 and Data2 have parameter = 1. If I click data1, the modal form will come in. The attribute checked has success become still checked. Next, I click data2, the attribute checked has success become unchecked. But if I back click data1, the attribute checked become unchecked. I don't know how to write code so that the attribute will back to begin.
How to fix it?
Aucun commentaire:
Enregistrer un commentaire