0

I want to add .val(tag) for checbox and .val(bahasa) for radio for displaying values of it in a Modal bootsrap. But it won't display any values of the selected radio nor checkbox in the Modal popup:( Does anyone know how to do the .val correctly for both radio and checkbox?

Here's my code:

      <script>
            $(document).on("click", "#tombolUbah", function() {
                let id = $(this).data('id');
                let judul = $(this).data('judul');
                let penulis = $(this).data('penulis');
                let tahun = $(this).data('tahun');
                let deskripsi = $(this).data('deskripsi');
                let gambar = $(this).data('gambar');
                let tag = $(this).data('tag');
                let bahasa = $(this).data('bahasa');

                $("#id_buku").val(id);
                    $("#judul_buku").val(judul);
                    $("#penulis_buku").val(penulis);
                    $("#tahun_terbit").val(tahun);
                    $("#deskripsi").val(deskripsi);
                    $("#gambar").val(gambar);
                    $("#tag").val(tag);
                    $("#bahasa").val(bahasa);
            })
        </script>

Thank you so much :)

  • 1
    This has nothing to do with PHP or mysql. Re-tag it with HTML and jQuery and show the related HTML so that we've got a [mre] of the issue. – ADyson Nov 21 '21 at 10:07
  • Does this answer your question? [Setting "checked" for a checkbox with jQuery](https://stackoverflow.com/questions/426258/setting-checked-for-a-checkbox-with-jquery) – steven7mwesigwa Nov 21 '21 at 10:56
  • For radio buttons. `element.attr('checked', true);` – steven7mwesigwa Nov 21 '21 at 10:58

1 Answers1

0

Getting values from the checkbox:

$( "input[type=checkbox][name=tag]:checked" ).val();

Getting values from the RadioBox:

$( "input[type=radio][name=bahasa]:checked" ).val();

reference