Nosean
1 year ago

jquery and add new row +data to select field

Posted 1 year ago by Nosean

Hello,

I have a problem I would like to insert via jquery in a table a new line. so far so good now i would like to pass data into a select field again and again.

my jquery code:

 $(document).ready(function(){
        var i=1;
        $("#add_row").click(function(){b=i-1;
            $('#addr'+i).html($('#addr'+b).html()).find('td:first-child').html(i+1);
            $('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>');
            i++;
        });
        $("#delete_row").click(function(){
            if(i>1){
                $("#addr"+(i-1)).html('');
                i--;
            }
            calc();
        });

        $('#tab_logic tbody').on('keyup change',function(){
            calc();
        });
        $('#tax').on('keyup change',function(){
            calc_total();
        });


    });

and my html Code:

 <tr id='addr0'>
    <td>1</td>
        <td>
               <select name="produkt[]" class="editSelect form-control form-control-sm">
                       @foreach($articles as $article)
                            <option value="2">{{ $article->article_name }}</option>
                       @endforeach
                </select>
           </td>
           <td><input type="number" name='qty[]' placeholder='Enter Qty' class="form-control qty" step="0" min="0"/></td>
           <td><input type="number" name='price[]' placeholder='Enter Unit Price' class="form-control price" step="0.00" min="0"/></td>
            <td><input type="number" name='total[]' placeholder='0.00' class="form-control total" readonly/></td>
</tr>

When I insert a new line I do not get the data $ article in line 2 anymore.

Why ?

Thank you

Please sign in or create an account to participate in this conversation.