newbe101
asked on
javascript calculate multiple textboxes
Hi all,
I have a javascript that takes values of textboxes and calculates them out. What I need to do is tweak my script so I can use multiple "products". I was thinking of appending a unique string in the beginning of the name/id of each textbox then using match expression or preg (??? not sure if they are correct terms) to have the script find the unique sets and calculate them accordingly.
ie.
set1= QTY11_somename * PRICE11_somename
set2= QTY5999_somename * PRICE5999_somename
set3=QTYd_somename * PRICEd_somename
then have the script take the sum of all of the sets to calculate the totals...
In my script so far, the names are hard coded (only 1 set). I need multiple sets with 1 set of totals... see my example:
I have a javascript that takes values of textboxes and calculates them out. What I need to do is tweak my script so I can use multiple "products". I was thinking of appending a unique string in the beginning of the name/id of each textbox then using match expression or preg (??? not sure if they are correct terms) to have the script find the unique sets and calculate them accordingly.
ie.
set1= QTY11_somename * PRICE11_somename
set2= QTY5999_somename * PRICE5999_somename
set3=QTYd_somename * PRICEd_somename
then have the script take the sum of all of the sets to calculate the totals...
In my script so far, the names are hard coded (only 1 set). I need multiple sets with 1 set of totals... see my example:
<script type="text/javascript">
onload = function(){
document.getElementById("calc").onclick = function(){
var form = this.form;
form.subtotal.value = (form.qty.value * form.price.value).toFixed(2);
form.tax.value = (form.subtotal.value * form.taxrate.value).toFixed(2);
form.total.value = ((form.qty.value * form.price.value) + (form.subtotal.value * form.taxrate.value)).toFixed(2);
}
}
</script>
<form>
Quantity: <input name='qty' /><br>
Price: <input name='price' /><br>
Tax Rate: <input name="taxrate" value="0.0825"/><br>
Subotal: <input name="subtotal" readonly="readonly" /><br>
Tax: <input name="tax" readonly="readonly" /><br>
Total: <input name="total" readonly="readonly" /><br>
<input type="button" value="Calculate" id="calc" />
</form>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
didn't get me anywhere... it just showed me how to seach a string, but I still don't know how to use it in my code...
ASKER
*bump*
ASKER
help, please...
ASKER
no more suggestions?
ASKER