Mitch
06-03-2008, 03:06 PM
Just spent 24 hours on a javascripting venture for .pdf forms. 1st time javascript attempt. Here was my problem:
Order form had fixed-quantity, fixed-price discounts. Tried if-then statements. didn't work. Searched all over the net - no real answers. Finally I found part of the solution online, part of the solution in a web design book. Solution works swimmingly. Hope someone can use it.
(solution probably isn't elegant, but neither am I).
My particular set up was a gridded set of fields where x-axis was different tee-shirt designs, y-axis was sizes small-xxlarge. Discount was to be applied based on quantity of design, regardless of size.
On the margin of the form, I set up hidden fields to calculate the separate rows. Across the bottom of y-axis, I set up hidden fields to multiply the different row values to the price, and apply discounts.
cell-naming conventions were as follows:
G1Sm G1M G1L...G1XX; G2Sm...G3Sm... (where customer fills in quantity)
G1Total, G2Total...G10Total (hidden fields for row quantity calculations)
G1$, G2$...G10$ (hidden fields for price calculation by row, i.e price * quantity)
Here is the Custom Javascript I used in the "G1$" - "G10$" that worked like a charm. Rather than using if...then conditional statements, I used switch...case statements, such as this:
//for G1$ pricing total. for G2$, replace every instance of G1 with G2, and on and on.//
var G1 = this.getField("G1Total").value;
switch( true ){
case ( G1 < "12" ):
event.value = (G1 * 11);
break;
case ( G1 < "49" ):
event.value = (G1 * 9.7);
break;
case ( G1 < "72" ):
event.value = (G1 * 9.4);
break;
case ( G1 < "143" ):
event.value = (G1 * 9.1);
break;
case (G1 > "144" ):
event.value = (G1 * 8.65);
break;
}
I really hope this helps somebody out there. Nobody had this answer for me, and other sites are miserable to search through.
I am off to sleep.
Order form had fixed-quantity, fixed-price discounts. Tried if-then statements. didn't work. Searched all over the net - no real answers. Finally I found part of the solution online, part of the solution in a web design book. Solution works swimmingly. Hope someone can use it.
(solution probably isn't elegant, but neither am I).
My particular set up was a gridded set of fields where x-axis was different tee-shirt designs, y-axis was sizes small-xxlarge. Discount was to be applied based on quantity of design, regardless of size.
On the margin of the form, I set up hidden fields to calculate the separate rows. Across the bottom of y-axis, I set up hidden fields to multiply the different row values to the price, and apply discounts.
cell-naming conventions were as follows:
G1Sm G1M G1L...G1XX; G2Sm...G3Sm... (where customer fills in quantity)
G1Total, G2Total...G10Total (hidden fields for row quantity calculations)
G1$, G2$...G10$ (hidden fields for price calculation by row, i.e price * quantity)
Here is the Custom Javascript I used in the "G1$" - "G10$" that worked like a charm. Rather than using if...then conditional statements, I used switch...case statements, such as this:
//for G1$ pricing total. for G2$, replace every instance of G1 with G2, and on and on.//
var G1 = this.getField("G1Total").value;
switch( true ){
case ( G1 < "12" ):
event.value = (G1 * 11);
break;
case ( G1 < "49" ):
event.value = (G1 * 9.7);
break;
case ( G1 < "72" ):
event.value = (G1 * 9.4);
break;
case ( G1 < "143" ):
event.value = (G1 * 9.1);
break;
case (G1 > "144" ):
event.value = (G1 * 8.65);
break;
}
I really hope this helps somebody out there. Nobody had this answer for me, and other sites are miserable to search through.
I am off to sleep.