简体   繁体   中英

Select2 Not active

<script>
    $(document).ready(function(){ 
        $("#btn-tambah-form").click(function(){ 
            var jumlah = parseInt($("#jumlah-form").val()); 
            var nextform = jumlah + 1;

            $("#insert-form").append(
                "<div class='row mb-10 p-10'>" +
                "   <div class='input-group col-md-2'>" +
                "          <?php $result = mysqli_query($conn, 'SELECT * FROM produk');?>" +
                "          <?php $jsArray = 'var idproduk = new Array();\n';?>" +
                "          <select class='form-control select2' id=\'idproduk"+nextform+"\' name=\'idproduk[]\' onchange=\'changeProduk"+nextform+"(this.value),sum();\' required>" +
                "          <option></option>" +
                "          <?php while ($row = mysqli_fetch_array($result)) {?>" +
                "               <?php echo '<option value=\'' . $row['idproduk'] . '\'>' . $row['produk_nama'] .  '</option>';?>" +
                "               <?php$jsArray .= 'idproduk[\'' . $row['idproduk'] . '\'] = {harga_beli:\'' . addslashes($row['harga_beli']) . '\',produk_satuan:\'' . addslashes($row['produk_satuan']) . '\'};\n';?>" +
                "          <?php }?>" +
                "              </select>" +
                "   </div>" +
                "</div>");
            $("#jumlah-form").val(nextform);
        });
        
        $("#btn-reset-form").click(function(){
            $("#insert-form").html(""); 
            $("#jumlah-form").val("1");
        });
    });
</script>

can someone help me. why my select2 not active when i put them on javascript. when i put them outside java they can run correct.

please help me how to solve this code.

There is problem with backslashed quotes, remove them. It should be all.

<select class='form-control select2' id='idproduk"+nextform+"' name='idproduk[]' onchange='changeProduk"+nextform+"(this.value),sum();' required>" +

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM