0

I'm trying to use dynamic rows and I have jquery to set dynamic options for a select, so I have HTML code and within it is a jquery, and this HTML I'm trying to use within a script.

Why it is not running? the line is the second one within the cols group.

<script>
$("#addrow").on("click", function () { var newRow = $("<tr>"); var cols = "";                              
    cols += '<td><input type="text" class="form-control" name="actividad' + counter + '"/></td>';
    cols += '<td class="col-sm-3"><div class="form-group"><script>$(document).ready(function() {$("#resp_act").change(function(){var respons_act=$("#resp_act").val();});})<\/script><select class="form-control resp_act" style="font: 15px arial;" type="number" name="resp_act' + counter + '" id="resp_act" required></select></div></td>';
    cols += '<td class="col-sm-2"><div class="form-group"><div class="input-group date" id="fec_ini_act"><input type="text" class="form-control fec_ini_act" name="fec_ini_act' + counter + '"/><span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span></div></div></td>';
    cols += '<td class="col-sm-2"><div class="form-group"><div class="input-group date" id="fec_fin_act"><input type="text" class="form-control fec_fin_act" name="fec_fin_act' + counter + '"/><span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span></div></div></td>';

    cols += '<td><input type="button" class="ibtnDel btn btn-md btn-danger "  
    value="Delete"></td>';
    
    newRow.append(cols);
    $("table.order-list").append(newRow);
    });
</script>
Paul T.
  • 4,703
  • 11
  • 25
  • 29
Rodhr2
  • 1
  • Check the browser console for possible javascript errors. – Paul T. Aug 07 '21 at 22:00
  • What is the exact problem? Please mention what do you expect to happen and whats the current output. Also it would be better if you can add a codepen example – Gagan Aug 07 '21 at 22:01
  • ...or a codepen-like interface can be made here on stackoverflow too. Use the `<>` icon on the editor toolbar. – Paul T. Aug 07 '21 at 22:01
  • IDs need to be unique. You shouldn't create a new `id="resp_act"` every time you click on the Add Row button. `$("#resp_act")` will always refer to the first one on the page, not the one you just added. – Barmar Aug 07 '21 at 23:39

0 Answers0