Hi,
I have a Javascript total calculation function within a php form that uses onBlur to show the client a running total of the dollar amount of items added: http://www.microtribe.com/dev4Tony/order881x2.php
And I have a linked external PHP file/script to email the results of the form to me. All works fine but I can't figure out how to grab the total dollar amount ("sub_total" ) created by the Javascript with this line:
document.getEle mentById('sub_t otal').innerHTM L = '$ ' + runningTotal.to Fixed(2);
Is there a way to have the Javascript send this variable to my php script?
Here is the full Javascript Function:
[CODE=javascript]/*Addition Function
*/
var elements = new Array();
function calculatePrice( price,me,id) {
var newValue = 0;
if (me.value == 0) {
document.getEle mentById('total ' + id).innerHTML = '';
} else if (me.value > 0) {
newValue = price * me.value;
document.getEle mentById('total ' + id).innerHTML = newValue.toFixe d(2);
}
elements['total' + id] = newValue.toFixe d(2);
calculateTotal( );
}
function calculateTotal( ) {
var runningTotal = 0;
for (var strCurrentKey in elements) {
runningTotal += parseFloat(elem ents[strCurrentKey]);
}
var sub = runningTotal.to Fixed(2);
var tax = sub * 0.00;
var total = sub * 1.08375;
document.getEle mentById('sub_t otal').innerHTM L = '$ ' + runningTotal.to Fixed(2);
document.getEle mentById('tax') .innerHTML = '$ ' + tax.toFixed(2);
document.getEle mentById('grand _total').innerH TML = '$ ' + total.toFixed(2 );
document.getEle mentById('field _subtotal').val ue = runningTotal.to Fixed(2);
document.getEle mentById('field _tax').value = tax.toFixed(2);
document.getEle mentById('field _total').value = total.toFixed(2 );
}
/*Parse number to currency format:
By Website Abstraction (www.wsabstract .com)
and Java-scripts.net (www.java-scripts.net)
*/
//Remove the $ sign if you wish the parse number to NOT include it
var wd;
function parseelement(te mpnum){
wd="w";
for (i=0;i<tempnum. length;i++){
if (tempnum.charAt (i)=="."){
wd="d";
break;
}
}
if (wd=="w") {
return tempnum+".00";
} else {
if (tempnum.charAt (tempnum.length-2)==".") {
return tempnum+"0";
} else {
tempnum=Math.ro und(tempnum*100 )/100;
return tempnum;
}
}
}
[/CODE]
Thanks!
Tony
I have a Javascript total calculation function within a php form that uses onBlur to show the client a running total of the dollar amount of items added: http://www.microtribe.com/dev4Tony/order881x2.php
And I have a linked external PHP file/script to email the results of the form to me. All works fine but I can't figure out how to grab the total dollar amount ("sub_total" ) created by the Javascript with this line:
document.getEle mentById('sub_t otal').innerHTM L = '$ ' + runningTotal.to Fixed(2);
Is there a way to have the Javascript send this variable to my php script?
Here is the full Javascript Function:
[CODE=javascript]/*Addition Function
*/
var elements = new Array();
function calculatePrice( price,me,id) {
var newValue = 0;
if (me.value == 0) {
document.getEle mentById('total ' + id).innerHTML = '';
} else if (me.value > 0) {
newValue = price * me.value;
document.getEle mentById('total ' + id).innerHTML = newValue.toFixe d(2);
}
elements['total' + id] = newValue.toFixe d(2);
calculateTotal( );
}
function calculateTotal( ) {
var runningTotal = 0;
for (var strCurrentKey in elements) {
runningTotal += parseFloat(elem ents[strCurrentKey]);
}
var sub = runningTotal.to Fixed(2);
var tax = sub * 0.00;
var total = sub * 1.08375;
document.getEle mentById('sub_t otal').innerHTM L = '$ ' + runningTotal.to Fixed(2);
document.getEle mentById('tax') .innerHTML = '$ ' + tax.toFixed(2);
document.getEle mentById('grand _total').innerH TML = '$ ' + total.toFixed(2 );
document.getEle mentById('field _subtotal').val ue = runningTotal.to Fixed(2);
document.getEle mentById('field _tax').value = tax.toFixed(2);
document.getEle mentById('field _total').value = total.toFixed(2 );
}
/*Parse number to currency format:
By Website Abstraction (www.wsabstract .com)
and Java-scripts.net (www.java-scripts.net)
*/
//Remove the $ sign if you wish the parse number to NOT include it
var wd;
function parseelement(te mpnum){
wd="w";
for (i=0;i<tempnum. length;i++){
if (tempnum.charAt (i)=="."){
wd="d";
break;
}
}
if (wd=="w") {
return tempnum+".00";
} else {
if (tempnum.charAt (tempnum.length-2)==".") {
return tempnum+"0";
} else {
tempnum=Math.ro und(tempnum*100 )/100;
return tempnum;
}
}
}
[/CODE]
Thanks!
Tony
Comment