lundi 4 juillet 2022

if the is_default column in database is 1 fill the checkbox

i want to fill checkbox using jquery when the is_default column in database is 1 so i get info from backend using getJSON() for check something like if the mobile number id was equal with data-id in input tag fill the check box for example my customers has 2 mobile number and i want just send sms to 1 number of it so i want to show wich mobile number is default using api and laravel and jquery

var tbody = '';
$.each(data, function(key, value) {
    tbody += '<tr>';
    tbody += '<td><div class="form-group"><div class="checkbox checkbox-primary"><input data-id="' + value.id + '" id="checkbox1" type="checkbox"><label for="checkbox1"></label></div></div></td>;'
    tbody += '</tr>';
});
$('tbody').append(tbody);
 
$.getJSON("http://localhost:8000/api/customers/mobile-numbers/checkbox/" + getID() + "", function(data) {
        $.each(data, function(key, value) {
        if (value.id === $('input#checkbox1').data('id')) {
            $('input#checkbox1').prop('checked', true);
        }
    });
});

in the above code fill all checkbox but i want to fill only the default mobile number something like this below code

$.getJSON("http://localhost:8000/api/customers/mobile-numbers/checkbox/" + getID() + "", function(data) {
        $.each(data, function(key, value) {
        if (value.id === $('input#checkbox1').data('id')) {
            $('input#checkbox1').data('id').prop('checked', true);
        }
    });
});

enter image description here

i want something like above code but i get error that can`t reading .prop after .data thanks for your helping




Aucun commentaire:

Enregistrer un commentaire