mike20599
01-03-2012, 08:25 PM
So I've got an order form that uses javascript to immediately calculate the price as soon as you enter the quantity that you want to order:
<form method="post" action="submitted.html" name="form">
<table id="order-table">
<tr>
<td>Widgets</td>
<td><input type="text" name="quantityWidgets" onchange="calculate()"></input></td>
<td> x </td>
<td>$650</td>
<td>=</td>
<td><input type="text" name="totalWidgets" disabled="disabled"></input></td>
</tr>
</table>
</form>
And here's the Javascript
function calculate(){
total = document.form.quantityWidgets.value * 650;
document.form.totalWidgets.value = total;
}
But that's just for 1 row and I have several rows of products. I could just use a different calculate() function for each row, but I'm trying to pass arguments into calculate() AND make it display the result in the proper place, but my syntax must be wrong.
...
<td><input type="text" name="quantityWidgets" onchange="calculate(quantityWidgets, 650, totalWidgets)"></input></td>
...
function calculate(quantity, price, total){
total = document.form.quantity.value * price;
document.form.total.value = total;
}
Can anyone help me please?
<form method="post" action="submitted.html" name="form">
<table id="order-table">
<tr>
<td>Widgets</td>
<td><input type="text" name="quantityWidgets" onchange="calculate()"></input></td>
<td> x </td>
<td>$650</td>
<td>=</td>
<td><input type="text" name="totalWidgets" disabled="disabled"></input></td>
</tr>
</table>
</form>
And here's the Javascript
function calculate(){
total = document.form.quantityWidgets.value * 650;
document.form.totalWidgets.value = total;
}
But that's just for 1 row and I have several rows of products. I could just use a different calculate() function for each row, but I'm trying to pass arguments into calculate() AND make it display the result in the proper place, but my syntax must be wrong.
...
<td><input type="text" name="quantityWidgets" onchange="calculate(quantityWidgets, 650, totalWidgets)"></input></td>
...
function calculate(quantity, price, total){
total = document.form.quantity.value * price;
document.form.total.value = total;
}
Can anyone help me please?