Forum Moderators: open
Can someone point me in the right direction?
rjbearcan, you would have to get good at the DOM (Document Object Model) commands. They would work very well here. Once you start using the DOM in Javascript, you will be hooked. It has become the standard nowadays in Javascript.
To start, in your form input fields, make sure you use ID attributes for all your quantity inputs like this:
<form>
<input id="q1" name="quantity1">
<input id="q1" name="quantity2">
<input readonly id="total" name="total">
<input type="button" onClick="getTotal();">
</form>
Note: Make sure your total input has a readonly attribute since you don't want your web visitors to change that since your javascript will do it.
Your javascript will do all the math for you via the DOM like this:
<script language="Javascript">
function getTotal() {
q1 = document.getElementById("q1").value;
q2 = document.getElementById("q2").value;
document.getElementById("total").value=q1 + q2;
}
</script>
That's all there is to it. I assumed you have 2 quantity inputs in your form. If you have more that two inputs in your form, then adjust accordingly.
If you really want to get fancy, have your PHP do it dynamically with an array.
I hope this helps,
Bruce