I have a Django invoice project, which has a back-end with products, manufacturer, etc.
Now there is a bill table with the columns headings: Product ID, Product Name, Product Price, Product Quantity, Taxes, Total, etc
With an add row button users can add rows for next product (ie, dynamically added rows).
What I now want is to bind jQuery event-listener with each Product ID columns(i.e. if I have 5 rows for 5 products, each row should have a Product ID column), such that as the user inputs (and edits) the product ID, I can - with the help of AJAX-fill the remaining columns.
My doubt is how to do that.
Also, as I get the AJAX data back, how do I identify the row to add the data (Product Name, Product Price, etc) to?
EDIT 1
I am generating the dynamic rows with the following code:
function generateTableRow() {
var emptyColumn = document.createElement('tr');
emptyColumn.innerHTML = '<td><a class="cut">-</a><span class="itemcode" contenteditable></span></td>' +
'<td colspan="2"><span contenteditable></span></td>' +
'<td><span contenteditable>100.00</span></td>' +
'<td><span contenteditable></span></td>' +
'<td><span contenteditable></span></td>'+
'<td><span contenteditable></span></td>' +
'<td><span contenteditable></span></td>'+
'<td><span contenteditable></span></td>' +
'<td><span contenteditable></span></td>' +
'<td><span contenteditable></span></td>' ;
return emptyColumn;
}
Note that the first span has class: "itemcode"
This is my jquery code:
$("#inventory_table .itemcode").on("focus", function(){
alert( "On focus for table inventory called." );
alert($(this).text());
});
the table id is "inventory_table".
This jquery event-listener is not getting bound with the dynamically generated rows.
Any help is appreciated.
Thanks