you can see in that JS, how I can grab an element in the rows, and
get the value, just loop through the rows, get each value, and add as
you go.
js doesn't need to be in the header, and sometimes, you have to put
down in your code, cuz you need to use values from witango or php, so
its down lower, and here:
much of this script is dynamically generated by php, but also easily
done in witango.
<script language="JavaScript">
<!--
function update_prices(){
var cnt=4;
var showqtyalert = 0;
for (i=1; i <= cnt; i++) {
var qty = document.getElementById('qty_'+i);
if (qty.value < 0 || qty.value > 499){
var showqtyalert = 1;
qty.value = 0;
}else {
var price = document.getElementById('fld_price_'+i);
var sub = document.getElementById('fld_subtotal_'+i);
var discount = 0;
//figure discount
if (qty.value >= 250){
discount = 46.25;
}else if (qty.value >= 100){
discount = 43.75;
}else if (qty.value >= 50){
discount = 40.63;
}else if (qty.value >= 25){
discount = 31.25;
}else if (qty.value >= 10){
discount = 18.75;
}else {
discount = 0;
}
var displaysub = document.getElementById('subtotal_'+i);
var displayprice = document.getElementById('price_'+i);
var calcdisc = ((100-discount)/100);
var discprice = calcdisc * price.value
var discprice = (Math.round(discprice*100))/100
var amt = discprice * qty.value;
sub.value = amt;
displaysub.innerHTML = formatCurrency(sub.value);
//alert('Discounts: '+calcdisc+' Price:'+price.value);
displayprice.innerHTML = formatCurrency(discprice);
}
if (showqtyalert){
alert('Quantities must be between 0 and 499.\r\n\r\nFor quantities
larger than 499 please contact \r\nBinder-USA directly or by
completing \r\nthe quotation request form on this site.');
showqtyalert = 0;
}
}
}
function formatCurrency(num) {
num = num.toString().replace(/\$|,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$ ' + num + '.' + cents);
}
update_prices();
//-->
</script>
--
Robert Garcia
President - BigHead Technology
VP Application Development - eventpix.com
13653 West Park Dr
Magalia, Ca 95954
ph: 530.645.4040 x222 fax: 530.645.4040
[EMAIL PROTECTED] - [EMAIL PROTECTED]
http://bighead.net/ - http://eventpix.com/
On Apr 10, 2007, at 6:26 PM, quicknote wrote:
Hi Robert
Thank you this is exactly the idea. However in my form I want to
add all the values in one column rather than do a sum for each row
as you have done.
I want the user to see the SUM before they do the submit to the
database.
I found this bit of code at your site. (There is a lot of code.)
<input type="text" name=qty[] id=qty_1 value="0"
onchange="update_prices()"style="font-family: Verdana, Helvetica,
sans-serif;font-size: 9px;width: 25px;font-weight: normal;text-
align: center;" />
But I couldn’t find the javascript in the header?
Would you be interestd in doing the javascript that I need?
Janet
From: Robert Garcia [mailto:[EMAIL PROTECTED]
Sent: Tuesday, April 10, 2007 8:47 PM
To: [email protected]
Subject: Re: Witango-Talk: FW: client side calculator
def javascript. You can probably rob some of the javascript I did
here:
http://www.binder-usa.com/
go to a section, like MINIATURE, and follow a product all the way
down, til you see quantities and how to order. The javascript does
sum, and also on the fly calculations and stuff. You can rob it
right out of source.
--
Robert Garcia
President - BigHead Technology
VP Application Development - eventpix.com
13653 West Park Dr
Magalia, Ca 95954
ph: 530.645.4040 x222 fax: 530.645.4040
[EMAIL PROTECTED] - [EMAIL PROTECTED]
http://bighead.net/ - http://eventpix.com/
On Apr 10, 2007, at 5:37 PM, quicknote wrote:
The witango TAF is looping through an array. Each row creates a
text box with a numerical value from the data base array.
The user can change the values. How can I show the new SUM at the
bottom without doing a SUBMIT. I imagine javascript is the answer.
Does anyone have any experience with this? Or any suggestions?
Thanks Janet
______________________________________________________________________
__
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf
______________________________________________________________________
__
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf
______________________________________________________________________
__
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf
________________________________________________________________________
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf