Note that there are some explanatory texts on larger screens.

plurals
  1. POajax script works only for the first row when page is refreshed
    primarykey
    data
    text
    <p>I have a problem my script. It purpose is to display some values in fields depending on value from dropdown select. When I fire other scripts that are adding or removing new rows into the form with the same fields, but different row id it stops working for the newly added rows.</p> <pre><code>&lt;script&gt; &lt;?php echo 'var lista = '.form_dropdown('produkt[]',$lista).';'?&gt; $(document).ready(function() { $('select[name="produkt[]"]').change(function() { var id = $('select[name="produkt[]"] option:selected').val(); var par = $(this).closest('tr').attr('id'); $.getJSON( '&lt;?php echo $head['site_link'];?&gt;index.php/faktura/pobierzProdukt/'+id, function(data){ var id = $('#'+par); $('input[name="pkwiu[]"]',id).val(data.product_pkwiu); $('input[name="netto[]"]',id).val(data.product_netto); $('input[name="vat[]"]',id).val(data.product_vat); $('input[name="brutto[]"]',id).val(data.product_brutto); $('input[name="jedn[]"]',id).val(data.product_jedn); }, 'json' ); }); $('#dodajWiersz').click(function() { var liczba = $('#produkty tr').length; var inputArray = [ '1', lista, '&lt;input type="text" name="pkwiu[]" class="short" readonly="readonly"/&gt;', '&lt;input type="text" name="netto[]" class="short" readonly="readonly"/&gt;', '&lt;input type="text" name="vat[]" class="mini" readonly="readonly"/&gt;', '&lt;input type="text" name="brutto[]" class="short" readonly="readonly"/&gt;', '&lt;input type="text" name="jedn[]" class="mini" readonly="readonly"/&gt;', '&lt;input type="text" name="ilosc[]" class="short"/&gt;', '&lt;input type="text" name="knetto[]" class="short" readonly="readonly"/&gt;', '&lt;input type="text" name="kvat[]" class="short" readonly="readonly"/&gt;', '&lt;input type="text" name="kbrutto[]" class="short" readonly="readonly"/&gt;' ]; var tdString = '&lt;td&gt;'+inputArray.join('&lt;/td&gt;&lt;td&gt;')+'&lt;/td&gt;'; if($('#produkty tbody tr').length&gt;0) { var row = '&lt;tr id="wiersz-'+liczba+'"&gt;'+tdString+'&lt;/tr&gt;'; $('#produkty').find('tbody').append(row); $('#produkty tr:last td:first-child').text(liczba); } else { var row = '&lt;tr id="wiersz-1"&gt;'+tdString+'&lt;/tr&gt;'; $('#produkty').find('tbody').append(row); } }); $('#usunWiersz').click(function() { $('#produkty').find('tbody tr:last').remove(); }); }); &lt;/script&gt; </code></pre> <p>I think the problem is with $(document).ready() function. But I can't solve it.</p> <p><strong>UPDATE:</strong> It seems that DOM is not updated. I can see the new HTML structure in Firebug but in the source view is the old structure. I think it matters.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload