Judas1012
June 3rd, 2004, 12:31 PM
I've got a simple JavaScript calculator in a form that works in Safari on Mac OS X and IE on Mac OS X and Windows machines -- the calculator doesn't work in any Netscape-derived browser, though... what am I doing wrong here?
<SCRIPT LANGUAGE="JavaScript" type="text/JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function customPrice() {
var height = bannerorder.customHeight.value;
var length = bannerorder.customLength.value;
var cost = bannerorder.customCost.value;
var num = height * length * 2.65;
if ((height == 2 && length == 4) || (height == 4 && length == 2)) {
alert("2 x 4 is a predefined size. Please select it from the menu to the left.");
bannerorder.customHeight.value = "";
bannerorder.customLength.value = "";
bannerorder.customCost.value = "$0.00";
bannerorder.size.focus();
return false;
}
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));
bannerorder.customCost.value = (((sign)?'':'-') + '$' + num + '.' + cents);
}
// End -->
</script>
"bannerorder" is the name of the form... here is how I call the method:
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr align="center" valign="middle">
<td><span class="style10">Height (ft.) </span></td>
<td><span class="style10">Length (ft.) </span></td>
</tr>
<tr align="center" valign="middle">
<td><input name="customHeight" type="text" id="customHeight" size="5" maxlength="3" onChange="customPrice()"></td>
<td><input name="customLength" type="text" id="customLength" size="5" maxlength="3" onChange="customPrice()"></td>
</tr>
</table>
<p>
<input name="CalcCost" type = button id="CalcCost" onClick="customPrice()" value="Calculate Cost">
</p>
<p><span class="style3"><strong>Cost of custom banner: </strong></span>
<br>
<input name="customCost" type="text" id="customCost" value="$0.00" size="10" maxlength="10" readonly>
Putting a semicolon at the end of "customPrice();" like that doesn't make a difference. Please help!
<SCRIPT LANGUAGE="JavaScript" type="text/JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function customPrice() {
var height = bannerorder.customHeight.value;
var length = bannerorder.customLength.value;
var cost = bannerorder.customCost.value;
var num = height * length * 2.65;
if ((height == 2 && length == 4) || (height == 4 && length == 2)) {
alert("2 x 4 is a predefined size. Please select it from the menu to the left.");
bannerorder.customHeight.value = "";
bannerorder.customLength.value = "";
bannerorder.customCost.value = "$0.00";
bannerorder.size.focus();
return false;
}
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));
bannerorder.customCost.value = (((sign)?'':'-') + '$' + num + '.' + cents);
}
// End -->
</script>
"bannerorder" is the name of the form... here is how I call the method:
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr align="center" valign="middle">
<td><span class="style10">Height (ft.) </span></td>
<td><span class="style10">Length (ft.) </span></td>
</tr>
<tr align="center" valign="middle">
<td><input name="customHeight" type="text" id="customHeight" size="5" maxlength="3" onChange="customPrice()"></td>
<td><input name="customLength" type="text" id="customLength" size="5" maxlength="3" onChange="customPrice()"></td>
</tr>
</table>
<p>
<input name="CalcCost" type = button id="CalcCost" onClick="customPrice()" value="Calculate Cost">
</p>
<p><span class="style3"><strong>Cost of custom banner: </strong></span>
<br>
<input name="customCost" type="text" id="customCost" value="$0.00" size="10" maxlength="10" readonly>
Putting a semicolon at the end of "customPrice();" like that doesn't make a difference. Please help!