I am trying to change a checkbox state but it does not seems to work. This is my code:
HTML:
<div class="input_container">
<label>Active</label>
<input type="checkbox" name="active"/>
</div>
jQuery/Ajax:
$.ajax({
url: 'includes/exproty.php',
type: 'post',
data: { 'product_id' : '100'},
success: function(data) {
var product_details = JSON.parse(data);
if (product_details.is_published) {
console.log("Works");
$("[name='active']").checked = true;
} else {
$("[name='active']").checked = false;
}
}
});
The console.log
inside the if
is used in order for me to confirm the condition is met and the code inside the if
is executed.
I also tried this:
$("[name='active']").prop('checked', true);
But it does not work either.
I know for certain the condition is met and is executing (thanks to the console.log
).
If needed any more information, ask for it and I will try to provide it. Thanks!
Aucun commentaire:
Enregistrer un commentaire