Creating a Total Amount Value.
Posted: Tue Mar 11, 2003 11:07 pm
Hey all, i have this code which a friend gave to me.. Now i've got it working but i want to add another value, which will give me the setupFee + theCost to create a total value.
http://www.dnxnet.com/?dnx=designquote
there you can have alook at what i'm talking about, and here is the javascript file:
I can understand if none of you even attempt this, but i'm a strong PHP coder, not javascript
. Thanks peoples.
http://www.dnxnet.com/?dnx=designquote
there you can have alook at what i'm talking about, and here is the javascript file:
Code: Select all
function init()
{
thePricing = new hostOption();
initialSetup = 150;
setupFee = initialSetup;
bTaxFree = false;
if (document.pricing.setup.value == 0)
{
document.pricing.setup.value = round(setupFee);
document.pricing.setupDisplay.value = format ( (setupFee * 1), 2 );
theCost = eval(document.pricing.spaceїdocument.pricing.space.selectedIndex].value);
document.pricing.cost.value = round(theCost );
document.pricing.costDisplay.value = format ( (theCost * 1 ), 2 );
}
document.pricing.setup.defaultValue = ( initialSetup );
document.pricing.setupDisplay.defaultValue = format ( ( initialSetup * 1 ), 2 );
document.pricing.cost.defaultValue = eval( ( document.pricing.spaceї0].value ) );
document.pricing.costDisplay.defaultValue = eval( format ( ( document.pricing.spaceї0].value ) * 1, 2 ) );
document.pricing.GST.defaultValue = calculateGST();
calculateGST();
for(j=0; j<document.pricing.length; j++)
{
if(document.pricing.elementsїj].name.indexOf("Units")== 0)
{
if(document.pricing.elementsїj-1].checked == false)
{
document.pricing.elementsїj].disabled = true;
}
}
}
theChoice = eval(document.pricing.spaceїdocument.pricing.space.selectedIndex].value);
document.pricing.GST.value = round(theGST);
}
function hostOption()
{ }
// Make sure select boxes are enabled if the check box is checked
function enableSelect ( checkbox, selectbox ) {
alert (checkbox.checked);
if ( checkbox.checked=="1" && selectbox.disabled == true )
{ selectbox.disabled = false }
}
function addCheck(checkBox, isSetup) { //v2.0
document.pricing.cost.value= round(eval(document.pricing.costDisplay.value / 1));
document.pricing.setup.value= round(eval(document.pricing.setupDisplay.value / 1));
if(isSetup)
{
if (checkBox.checked=="1")
{
document.pricing.setup.value = round(eval(document.pricing.setup.value) + eval(checkBox.value));
}
else
{
document.pricing.setup.value = round(eval(document.pricing.setup.value) - eval(checkBox.value));
}
setupFee = document.pricing.setup.value;
document.pricing.setupDisplay.value = format ( setupFee * 1, 2 );
}
else
{
if (checkBox.checked=="1")
{
document.pricing.cost.value = round(eval(document.pricing.cost.value) + eval(checkBox.value));
}
else
{
document.pricing.cost.value = round(eval(document.pricing.cost.value) - eval(checkBox.value));
}
theCost = document.pricing.cost.value;
document.pricing.costDisplay.value = format ( theCost * 1, 2 );
}
calculateGST();
}
function format ( expr, decPlaces ) {
var str= "" + Math.round ( eval ( expr ) * Math.pow ( 10, decPlaces ) )
while ( str.length <= decPlaces ) {
str = "0" + str }
var decpoint = str.length - decPlaces
var value=str.substring ( 0, decpoint ) + "." + str.substring ( decpoint, str.length )
return value.toString();
}
function calcdomain(fieldname){
// var pricearray = new Array ('0','53.90','105.60','151.80','193.60','242.00','313.50','365.20','418.00','469.70','522.50');
var pricearray = new Array ('0','0','69.00','103.50','138.00','172.50','207.00','241.50','276.00','310.50','345.00');
var newprice;
var years;
eval("years=document.domaincalc."+fieldname+"Years.optionsїdocument.domaincalc."+fieldname+"Years.selectedIndex].text" );
newprice=pricearrayїyears];
eval("document.domaincalc."+fieldname+"Price.value = '"+newprice+"'");
}
function addChoice(choiceValue){
document.pricing.cost.value= round(eval(document.pricing.costDisplay.value / 1));
document.pricing.setup.value= round(eval(document.pricing.setupDisplay.value / 1));
document.pricing.cost.value = round((eval(document.pricing.cost.value) + eval(choiceValueїchoiceValue.selectedIndex].value) - eval(theChoice)));
theChoice = eval(choiceValueїchoiceValue.selectedIndex].value);
theCost = document.pricing.cost.value;
setupFee = document.pricing.setup.value;
document.pricing.costDisplay.value = format ( ( theCost * 1 ), 2 )
document.pricing.setupDisplay.value = format ( ( setupFee * 1 ), 2 )
calculateGST();
}
function changeChoice(checkBox, isSetup, theID, units) {
document.pricing.cost.value= round(eval(document.pricing.costDisplay.value / 1));
document.pricing.setup.value= round(eval(document.pricing.setupDisplay.value / 1));
if (checkBox.checked=="1")
{
if(isSetup)
{
document.pricing.setup.value = round(eval(document.pricing.setup.value) - thePricingїtheID] + (eval(checkBox.value) * units));
setupFee = document.pricing.setup.value;
document.pricing.setupDisplay.value = format ( setupFee * 1, 2 )
}
else
{
document.pricing.cost.value = round(eval(document.pricing.cost.value) - thePricingїtheID] + (eval(checkBox.value) * units));
theCost = document.pricing.cost.value;
document.pricing.costDisplay.value = format ( theCost * 1, 2 )
}
}
calculateGST();
thePricingїtheID] = checkBox.value * units;
}
function mrChoice(checkBox, isSetup, theID, units, unable) { //v2.0
document.pricing.cost.value= round(eval(document.pricing.costDisplay.value / 1));
document.pricing.setup.value= round(eval(document.pricing.setupDisplay.value / 1));
if(thePricingїtheID] == null)
{
thePricingїtheID] = "0";
}
if(isSetup)
{
if (checkBox.checked=="1")
{
unable.disabled = false;
document.pricing.setup.value = round(eval(document.pricing.setup.value) - thePricingїtheID] + (eval(checkBox.value) * units));
thePricingїtheID] = checkBox.value * units;
}
else
{
unable.disabled = true;
document.pricing.setup.value = round(eval(document.pricing.setup.value) - thePricingїtheID]);
thePricingїtheID] = 0;
}
setupFee = document.pricing.setup.value;
document.pricing.setupDisplay.value = format ( setupFee * 1, 2 )
}
else
{
if (checkBox.checked=="1")
{
unable.disabled = false;
document.pricing.cost.value = round(eval(document.pricing.cost.value) - thePricingїtheID] + (eval(checkBox.value) * units));
thePricingїtheID] = checkBox.value * units;
}
else
{
unable.disabled = true;
document.pricing.cost.value = round(eval(document.pricing.cost.value) - thePricingїtheID]);
thePricingїtheID] = 0;
}
theCost = document.pricing.cost.value;
document.pricing.costDisplay.value = format ( theCost * 1, 2 )
}
calculateGST();
}
function doFocus(checkBox, theID, units, zap)
{
thePricingїtheID] = checkBox.value * units;
}
function calculateGST()
{
theGST = round((eval(document.pricing.cost.value) + eval(document.pricing.setup.value)) / 1);
if (bTaxFree)
document.pricing.GST.value = "0";
else
document.pricing.GST.value = round(theGST);
}
function round(price)
{
newPrice = Math.round(price*Math.pow(10,2))/Math.pow(10,2);
string = "" + newPrice;
number = string.length - string.indexOf('.');
if (number == 2)
return newPrice + '0';
else
return newPrice;
}
function taxFree(strGst) {
if (strGst == "Yes") {
bTaxFree = false;
document.pricing.GST.value = round(theGST);
}
else {
bTaxFree = true;
document.pricing.GST.value = "0";
}
}
function newWin(url) {
window.open(url);
window.close();
}