mardi 20 janvier 2015

adding values to unknown element ids in jquery


Vote count:

0




I have a dynamically created form in that a user can click "add row" and get a new element in the form.


some of the elements are quantity and price. I want to change values based on what users enter. so if he chooses qty=4 and price=10 i want amount to =40.


I dont know what to use as the selector for price or amount since input ids are dynamically generated.



var form = "<tr><td>Quantity</td>
<td><input class='qty' type='text' id='qty[]' name='qty[]'></td>";

form += "<td>Part Num</td>
<td><input type='text' id='part[]' name='part[]'></td>";

form += "<td>Description</td>
<td><input class='desc' type='text' id='desc[]' name='desc[]'></td>";

form += "<td>Unit Price</td>
<td><input type='text' id='price[]' name='price[]'></td>";

form += "<td>Amount</td>
<td><input type='text' id='amount[]' name='amount'></td></tr>";

$('#addItem').click(function(){
$('#itemsTable').append(form);
});


$(document).on('change','.qty',function(){

//What can i use as a selector for value_of_qty and value_of_price here???

//var total = $(value_of_qty) * $(value_of_price);
//$(id_of_amount).val(total);
});


asked 1 min ago







adding values to unknown element ids in jquery

Aucun commentaire:

Enregistrer un commentaire