Как сдать авто инкремент динамическое поле идентификатор в код на JavaScript ? Я использую автозаполнение select с помощью раскрывающегося списка (typehead)..
1.the auto search & select is working in first row textbox only .. 2.when i add 2nd row the autosearch is not working . thank you
Что я уже пробовал:
<table id="invoice-item-table" class="table table-bordered"> <tr> <th width="7%">Sr No.</th> <th width="20%">Item Name</th> <th width="5%">Quantity</th> <th width="5%">Price</th> <th width="10%">Actual Amt.</th> <th width="12.5%" rowspan="2">Total</th> <th width="3%" rowspan="2"></th> </tr> <tr> <tr> <td><span id="sr_no">1</span></td> <td><input type="text" name="item_name[]" id="item_name1" autocomplete="off" class="form-control input-sm" /></td> <td><input type="text" name="order_item_quantity[]" id="order_item_quantity1" data-srno="1" class="form-control input-sm order_item_quantity" /></td> <td><input type="text" name="order_item_price[]" id="order_item_price1" data-srno="1" class="form-control input-sm number_only order_item_price" /></td> <td><input type="text" name="order_item_actual_amount[]" id="order_item_actual_amount1" data-srno="1" class="form-control input-sm order_item_actual_amount" readonly /></td>
<td><input type="text" name="order_item_final_amount[]" id="order_item_final_amount1" data-srno="1" readonly class="form-control input-sm order_item_final_amount" /></td> <td></td> </tr> </table> <div align="right"> <button type="button" name="add_row" id="add_row" class="btn btn-success btn-xs">+</button> </div> </td> </tr> <tr> <td align="right">Total</td> <td align="right"><span id="final_total_amt"></span></td> </tr> <tr> <td colspan="2"></td> </tr> <tr> <td colspan="2" align="center"> <input type="hidden" name="total_item" id="total_item" value="1" /> <input type="submit" name="create_invoice" id="create_invoice" class="btn btn-info" value="Create" /> </td> </tr> </table>
<td><input type="text" name="order_item_final_amount[]" id="order_item_final_amount1" data-srno="1" readonly class="form-control input-sm order_item_final_amount" /></td> <td></td> </tr> </table> <div align="right"> <button type="button" name="add_row" id="add_row" class="btn btn-success btn-xs">+</button> </div> </td> </tr> <tr> <td align="right">Total</td> <td align="right"><span id="final_total_amt"></span></td> </tr> <tr> <td colspan="2"></td> </tr> <tr> <td colspan="2" align="center"> <input type="hidden" name="total_item" id="total_item" value="1" /> <input type="submit" name="create_invoice" id="create_invoice" class="btn btn-info" value="Create" /> <input type="submit" name="create_invoice" id="create_invoice" class="btn btn-info" value="Create" /> <a href="ord.php" class="btn btn-info" role="button">Back</a> </td> </tr> </table>
<script> $(document).ready(function(){ $('#item_name1').typeahead({ source: function(query, result) { $.ajax({ url:"fetch.php", method:"POST", data:{query:query}, dataType:"json", success:function(data) { result($.map(data, function(item){ return item; })); } }) } }); });
<script> $(document).ready(function(){ var final_total_amt = $('#final_total_amt').text(); var count = 1; $(document).on('click', '#add_row', function(){ count++; $('#total_item').val(count); var html_code = ''; html_code += '<tr id="row_id_'+count+'">'; html_code += '<td><span id="sr_no">'+count+'</span></td>'; html_code += '<td><input type="text" name="item_name[]" id="item_name'+count+'" class="form-control input-sm" /></td>'; html_code += '<td><input type="text" name="order_item_quantity[]" id="order_item_quantity'+count+'" data-srno="'+count+'" class="form-control input-sm number_only order_item_quantity" /></td>'; html_code += '<td><input type="text" name="order_item_price[]" id="order_item_price'+count+'" data-srno="'+count+'" class="form-control input-sm number_only order_item_price" /></td>'; html_code += '<td><input type="text" name="order_item_actual_amount[]" id="order_item_actual_amount'+count+'" data-srno="'+count+'" class="form-control input-sm order_item_actual_amount" readonly /></td>';
html_code += '<td><input type="text" name="order_item_final_amount[]" id="order_item_final_amount'+count+'" data-srno="'+count+'" readonly class="form-control input-sm order_item_final_amount" /></td>'; html_code += '<td><button type="button" name="remove_row" id="'+count+'" class="btn btn-danger btn-xs remove_row">X</button></td>'; html_code += '</tr>'; $('#invoice-item-table').append(html_code); });