Post data json inside checkbox and images
Hi this is my whole js, i'm building some edit products which is inside modal bootsrap
- $('.edit_button').on("click", function(e) {
- var id = $(this).data('id');
- $.ajax({
- url: base_url + "product/edit/"+id,
- type: "GET",
- dataType: "JSON",
- success: function(data)
- {
- //i need to show data from database in checkbox and images in by name input type checkbox
-
- $('[name="id_brand"]').val(data.id_brand);
- $('[name="merk"]').val(data.name_brand);
- $('[name="id_tipe"]').val(data.id_tipe);
- $('[name="tipe"]').val(data.name_tipe);
- $('[name="product_toko"]').val(data.product_toko);
- $('[name="product_harga"]').val(data.product_harga);
- $('[name="product_keterangan"]').val(data.product_keterangan);
-
-
- $('#modal_form').modal('show'); // show bootstrap modal when complete loaded
- $('.modal-title').text('Edit Product'); // Set title to Bootstrap modal title
-
- },
- error: function (jqXHR, textStatus, errorThrown)
- {
- alert('Error get data from ajax');
- }
- });
- });
-
then i'm trying to make var for
name_tipe but gpot errors
my problem is how can i put values from database inside checkbox or images, here is i'm trying to pu calues inside checkbox but got errors
val is not defined
-
$.ajax({
url: base_url + "product/edit/"+id,
type: "GET",
dataType: "JSON",
success: function(data)
{
//here is data from database which will show in modal
var name_tipe= val(data.name_tipe); //consider it for check bok
if (name_tipe !=='') {
alert('check box has value');
$('.myCheckbox').prop('checked', true);
}
else
{
alert('check box has value');
$('.myCheckbox').prop('checked', false);
}
});
Thanks