E
Ed
Hoping someone an assist me urgently. I would truly appreciate and help.
I have a form and prices are based on 'price break'.
1.The price break fields work fine, but I cannot for the life of me add more
than one to a page.
2. Also need to add the two results to a 'total' field. (See code attached).
Many thanks in advance.
Sample code ...
<HEAD>
</HEAD>
<BODY onLoad="findPrice();">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var max_hsunits1 = 1000; // quantities in excess of max_hsunits1 all have
the same unit price
var currency = "$"; // currency sign used in 'formatMessage()'
// Edit this function to reflect discount prices!
function getDiscountPrice(hsunits1) {
// Note: Work way down from max to min amounts!
if (hsunits1 >= max_hsunits1) return 18;
if (hsunits1 >= 750) return 20;
if (hsunits1 >= 500) return 25;
if (hsunits1 >= 250) return 28;
if (hsunits1 >= 150) return 30;
if (hsunits1 >= 75) return 31;
if (hsunits1 >= 50) return 40;
if (hsunits1 >= 25) return 45;
if (hsunits1 >= 10) return 47;
if (hsunits1 >= 5) return 50;
if (hsunits1 >= 1) return 55;
if (hsunits1 <= 0) return 0;
}
function getNumberOfUnits() {
var hsunits1 = document.Hypersnap.hsunits1.value;
return (hsunits1 == "") ? 0 : hsunits1;
}
function showResult(result) {
// adjust the following line if result must popup somewhere else
document.Hypersnap.hsresult1.value = result;
}
function formatMessage(hsunits1, unit_price) {
return hsunits1 + " * " + currency + formatPrice(unit_price) + " = " +
currency + formatPrice(hsunits1 * unit_price);
}
// AltUnits (alternate hsunits1): add extra hsunits1 to reach minimum for
next discount price
function getAltUnits(hsunits1) {
var discount_price = getDiscountPrice(hsunits1);
if (hsunits1 < max_hsunits1) do { hsunits1++ } while (discount_price ==
getDiscountPrice(hsunits1));
return hsunits1;
}
function findPrice() {
var hsunits1 = getNumberOfUnits();
var unit_price = getDiscountPrice(hsunits1);
var alt_hsunits1 = getAltUnits(hsunits1);
var alt_unit_price = getDiscountPrice(alt_hsunits1);
var result;
if ((hsunits1 * unit_price) < (alt_hsunits1 * alt_unit_price))
result = formatMessage(hsunits1, unit_price);
else
result = formatMessage(alt_hsunits1, alt_unit_price);
showResult(result);
}
function formatPrice(value) {
var result= Math.floor(value) + ".";
var cents = 100 * (value-Math.floor(value)) + 0.5;
result += Math.floor(cents / 10);
result += Math.floor(cents % 10);
return result;
}
function filterNonNumeric(field) {
var result = new String();
var numbers = "0123456789";
var chars = field.value.split(""); // create array
for (i = 0; i < chars.length; i++) {
if (numbers.indexOf(chars) != -1) result += chars;
}
if (field.value != result) field.value = result;
}
// End -->
</script>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var max_hsunits2 = 1000; // quantities in excess of max_hsunits2 all have
the same unit price
var currency = "$"; // currency sign used in 'formatMessage2()'
// Edit this function to reflect your discount prices!
function getDiscountPrice2(hsunits2) {
// Note: It is important to work your way down from max to min amounts!
if (hsunits2 >= max_hsunits2) return 18;
if (hsunits2 >= 750) return 20;
if (hsunits2 >= 500) return 25;
if (hsunits2 >= 250) return 28;
if (hsunits2 >= 150) return 30;
if (hsunits2 >= 75) return 31;
if (hsunits2 >= 50) return 40;
if (hsunits2 >= 25) return 45;
if (hsunits2 >= 10) return 47;
if (hsunits2 >= 5) return 50;
if (hsunits2 >= 1) return 55;
if (hsunits2 <= 0) return 0;
}
function getNumberOfUnits2() {
var hsunits2 = document.Hypersnap.hsunits2.value2;
return (hsunits2 == "") ? 0 : hsunits2;
}
function showResult2(result2) {
// adjust the following line if result2 must popup somewhere else
document.Hypersnap.hsresult22.value2 = result2;
}
function formatMessage2(hsunits2, unit_price2) {
return hsunits2 + " * " + currency + formatPrice2(unit_price2) + " = " +
currency + formatPrice2(hsunits2 * unit_price2);
}
// AltUnits2 (alternate hsunits2): add extra hsunits2 to reach minimum for
next discount price
function getAltUnits2(hsunits2) {
var discount_price2 = getDiscountPrice2(hsunits2);
if (hsunits2 < max_hsunits2) do { hsunits2++ } while (discount_price2 ==
getDiscountPrice2(hsunits2));
return hsunits2;
}
function findPrice2() {
var hsunits2 = getNumberOfUnits2();
var unit_price2 = getDiscountPrice2(hsunits2);
var alt_hsunits2 = getAltUnits2(hsunits2);
var alt_unit_price2 = getDiscountPrice2(alt_hsunits2);
var result2;
if ((hsunits2 * unit_price2) < (alt_hsunits2 * alt_unit_price2))
result2 = formatMessage2(hsunits2, unit_price2);
else
result2 = formatMessage2(alt_hsunits2, alt_unit_price2);
showResult2(result2);
}
function formatPrice2(value2) {
var result2= Math.floor(value2) + ".";
var cents = 100 * (value-Math.floor(value2)) + 0.5;
result2 += Math.floor(cents / 10);
result2 += Math.floor(cents % 10);
return result2;
}
function filterNonNumeric(field) {
var result2 = new String();
var numbers = "0123456789";
var chars = field.value.split(""); // create array
for (i = 0; i < chars.length; i++) {
if (numbers.indexOf(chars) != -1) result2 += chars;
}
if (field.value2 != result2) field.value = result2;
}
// End -->
</script>
<form name="Hypersnap" method="post">
<p><font face="Arial" size="2"><b>Number of Users Required :</b></font>
<input type=text value="1" name="hsunits1" onkeydown="findPrice()"
onKeyUp="filterNonNumeric(this); findPrice()" onkeypress="findPrice()"
size="4" style="font-weight:bold; text-align:center;">
<input type=text onfocus="this.blur()" name="hsresult1" size="24"
style="border:0; font-weight:bold;">
<br><font face="Arial" size="2"><b>Number of Users Required :</b></font>
<input type=text value="1" name="hsunits2" onkeydown="findPrice()"
onKeyUp="filterNonNumeric(this); findPrice()" onkeypress="findPrice()"
size="4" style="font-weight:bold; text-align:center;">
<input type=text onfocus="this.blur()" name="hsresult2" size="24"
style="border:0; font-weight:bold;">
</form>
<form name="form1">
<p align="left"><font
color="black"><strong>Total Sales
&nbs
p; <input
type="text" name="hstotal" value="0.00" size="16"
onchange="ComputeForm()"
style="font-family:Arial; font-style:normal;
font-weight:bolder; font-size:11pt; color:white; background-color:black;"
language="JavaScript"></strong></font></p>
</form>
</html>
I have a form and prices are based on 'price break'.
1.The price break fields work fine, but I cannot for the life of me add more
than one to a page.
2. Also need to add the two results to a 'total' field. (See code attached).
Many thanks in advance.
Sample code ...
<HEAD>
</HEAD>
<BODY onLoad="findPrice();">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var max_hsunits1 = 1000; // quantities in excess of max_hsunits1 all have
the same unit price
var currency = "$"; // currency sign used in 'formatMessage()'
// Edit this function to reflect discount prices!
function getDiscountPrice(hsunits1) {
// Note: Work way down from max to min amounts!
if (hsunits1 >= max_hsunits1) return 18;
if (hsunits1 >= 750) return 20;
if (hsunits1 >= 500) return 25;
if (hsunits1 >= 250) return 28;
if (hsunits1 >= 150) return 30;
if (hsunits1 >= 75) return 31;
if (hsunits1 >= 50) return 40;
if (hsunits1 >= 25) return 45;
if (hsunits1 >= 10) return 47;
if (hsunits1 >= 5) return 50;
if (hsunits1 >= 1) return 55;
if (hsunits1 <= 0) return 0;
}
function getNumberOfUnits() {
var hsunits1 = document.Hypersnap.hsunits1.value;
return (hsunits1 == "") ? 0 : hsunits1;
}
function showResult(result) {
// adjust the following line if result must popup somewhere else
document.Hypersnap.hsresult1.value = result;
}
function formatMessage(hsunits1, unit_price) {
return hsunits1 + " * " + currency + formatPrice(unit_price) + " = " +
currency + formatPrice(hsunits1 * unit_price);
}
// AltUnits (alternate hsunits1): add extra hsunits1 to reach minimum for
next discount price
function getAltUnits(hsunits1) {
var discount_price = getDiscountPrice(hsunits1);
if (hsunits1 < max_hsunits1) do { hsunits1++ } while (discount_price ==
getDiscountPrice(hsunits1));
return hsunits1;
}
function findPrice() {
var hsunits1 = getNumberOfUnits();
var unit_price = getDiscountPrice(hsunits1);
var alt_hsunits1 = getAltUnits(hsunits1);
var alt_unit_price = getDiscountPrice(alt_hsunits1);
var result;
if ((hsunits1 * unit_price) < (alt_hsunits1 * alt_unit_price))
result = formatMessage(hsunits1, unit_price);
else
result = formatMessage(alt_hsunits1, alt_unit_price);
showResult(result);
}
function formatPrice(value) {
var result= Math.floor(value) + ".";
var cents = 100 * (value-Math.floor(value)) + 0.5;
result += Math.floor(cents / 10);
result += Math.floor(cents % 10);
return result;
}
function filterNonNumeric(field) {
var result = new String();
var numbers = "0123456789";
var chars = field.value.split(""); // create array
for (i = 0; i < chars.length; i++) {
if (numbers.indexOf(chars) != -1) result += chars;
}
if (field.value != result) field.value = result;
}
// End -->
</script>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var max_hsunits2 = 1000; // quantities in excess of max_hsunits2 all have
the same unit price
var currency = "$"; // currency sign used in 'formatMessage2()'
// Edit this function to reflect your discount prices!
function getDiscountPrice2(hsunits2) {
// Note: It is important to work your way down from max to min amounts!
if (hsunits2 >= max_hsunits2) return 18;
if (hsunits2 >= 750) return 20;
if (hsunits2 >= 500) return 25;
if (hsunits2 >= 250) return 28;
if (hsunits2 >= 150) return 30;
if (hsunits2 >= 75) return 31;
if (hsunits2 >= 50) return 40;
if (hsunits2 >= 25) return 45;
if (hsunits2 >= 10) return 47;
if (hsunits2 >= 5) return 50;
if (hsunits2 >= 1) return 55;
if (hsunits2 <= 0) return 0;
}
function getNumberOfUnits2() {
var hsunits2 = document.Hypersnap.hsunits2.value2;
return (hsunits2 == "") ? 0 : hsunits2;
}
function showResult2(result2) {
// adjust the following line if result2 must popup somewhere else
document.Hypersnap.hsresult22.value2 = result2;
}
function formatMessage2(hsunits2, unit_price2) {
return hsunits2 + " * " + currency + formatPrice2(unit_price2) + " = " +
currency + formatPrice2(hsunits2 * unit_price2);
}
// AltUnits2 (alternate hsunits2): add extra hsunits2 to reach minimum for
next discount price
function getAltUnits2(hsunits2) {
var discount_price2 = getDiscountPrice2(hsunits2);
if (hsunits2 < max_hsunits2) do { hsunits2++ } while (discount_price2 ==
getDiscountPrice2(hsunits2));
return hsunits2;
}
function findPrice2() {
var hsunits2 = getNumberOfUnits2();
var unit_price2 = getDiscountPrice2(hsunits2);
var alt_hsunits2 = getAltUnits2(hsunits2);
var alt_unit_price2 = getDiscountPrice2(alt_hsunits2);
var result2;
if ((hsunits2 * unit_price2) < (alt_hsunits2 * alt_unit_price2))
result2 = formatMessage2(hsunits2, unit_price2);
else
result2 = formatMessage2(alt_hsunits2, alt_unit_price2);
showResult2(result2);
}
function formatPrice2(value2) {
var result2= Math.floor(value2) + ".";
var cents = 100 * (value-Math.floor(value2)) + 0.5;
result2 += Math.floor(cents / 10);
result2 += Math.floor(cents % 10);
return result2;
}
function filterNonNumeric(field) {
var result2 = new String();
var numbers = "0123456789";
var chars = field.value.split(""); // create array
for (i = 0; i < chars.length; i++) {
if (numbers.indexOf(chars) != -1) result2 += chars;
}
if (field.value2 != result2) field.value = result2;
}
// End -->
</script>
<form name="Hypersnap" method="post">
<p><font face="Arial" size="2"><b>Number of Users Required :</b></font>
<input type=text value="1" name="hsunits1" onkeydown="findPrice()"
onKeyUp="filterNonNumeric(this); findPrice()" onkeypress="findPrice()"
size="4" style="font-weight:bold; text-align:center;">
<input type=text onfocus="this.blur()" name="hsresult1" size="24"
style="border:0; font-weight:bold;">
<br><font face="Arial" size="2"><b>Number of Users Required :</b></font>
<input type=text value="1" name="hsunits2" onkeydown="findPrice()"
onKeyUp="filterNonNumeric(this); findPrice()" onkeypress="findPrice()"
size="4" style="font-weight:bold; text-align:center;">
<input type=text onfocus="this.blur()" name="hsresult2" size="24"
style="border:0; font-weight:bold;">
</form>
<form name="form1">
<p align="left"><font
color="black"><strong>Total Sales
&nbs
p; <input
type="text" name="hstotal" value="0.00" size="16"
onchange="ComputeForm()"
style="font-family:Arial; font-style:normal;
font-weight:bolder; font-size:11pt; color:white; background-color:black;"
language="JavaScript"></strong></font></p>
</form>
</html>