Click to See Complete Forum and Search --> : using a for statement that collects hidden fields for calculations


dv6cougar
10-19-2003, 07:06 PM
i have this down for the most part now, however, i cannot figure out how I can grab all the prices while it's looping.

so i have the values maybe 1, 4, 450 and 350, the total should be 805.

here's my script, any help is greatly appreciated.


<script language="javascript">
function compute_first(f) {
var msg = '';
var hidden_fields = '';
var price_array = new Array(f.length);
for(var i = 0; i < f.length; i++) {
var e = f.elements[i];

if(e.type == "hidden") {

hidden_fields += '\n' + e.name + ' with value of ' + e.value;

var totalled = e.value;
var totald += parseFloat(totalled) + parseFloat(totalled);

}
}

hidden_fields += '\n\n total = ' + totald;


msg += 'The following fields are hidden in form f1:\n\n';
msg += hidden_fields;

document.f1.final_pr.value = totald;
var shipping = parseFloat(<? echo $final_ship; ?>);
var ship_total = parseFloat(totald) + parseFloat(shipping);
document.f1.final_shipping.value = shipping;
document.f1.final_charge.value = ship_total;

}

</script>


i have tried mahy different routes to there may be a few unnecessary variables set and such in the script that are not used.

i have called alert(msg); to see what goes on here, and the prices are going up from e.value correctly in that, but not when i go to add them.

dv6cougar
10-20-2003, 09:21 AM
come on, someone has to know :(