code for multiplication javascript that will multiply unitprice and quantity and will display the result to the another textbox(total)
<script>
function calculate() {
var myunitprice = document.getElementById('unitprice').value;
var myquantity = document.getElementById('quantity').value;
var result = document.getElementById('total');
var myResult = myunitprice * myquantity;
result.value = myResult.toFixed(2); }
</script>
Here's the another code for dynamic textbox, when select it will add another textbox.
<script>
var php = '';
$('#children').on('change', function() {
children = $(this).val();
html = '';
for (var i = 0; i < children; i++) {
html += '<table><tr><td><label><b>Item Purchase</b></label><input type="text" id="item' + i + '" name="child' + i + 'Name" /><label>Amount</label><input type="text" id="amount' + i + '" name="child' + i + 'Name" /><label>Unit</label><input type="text" id="unit' + i + '" name="child' + i + 'Name" /><label>Quantity</label><input type="text" id="quantity' + i + '" name="child' + i + 'Name" onchange="calculate()" /><label>Unit Price</label><input type="text" name="child' + i + 'Age" id="unitprice' + i + '" onchange="calculate()" /><td>';
}
$('#kidsFields').html(html);
$('#kidsFields').append('<br><td><input type="submit" value="Submit" /></td></tr></table>');
$('.ui-page').trigger('create');
});
</script>
Here's my html
<form data-ajax="false" method="post" action="purchasingAddRecords.php">
<center>
<table>
<tr>
<td>
<td>
<div data-role="content">
<li data-role="fieldcontain">
<label for="children" class="select">Add</label>
<select name="children" id="children" data-mini="true">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</li>
<div id="kidsFields"></div>
</div>
the problem is that when i put data on the textbox(quantity and unitprice), it doesn't calculate.