0

我正在创建一个应用程序来估计丝网印刷的工作,但我现在被困住了。这是迄今为止的表格http://www.redfivedesigns.com/mprintsapp/index2.html。首先,我需要做的是添加正面颜色 + 背面颜色 + 其他颜色 + 价格,然后将该总数乘以数量,并将该总数添加到其余费用中。此外,我需要有关如何将用户定义的价格和数量添加为文本输入的帮助。

//Set up an associative array 
//The keys represent the front colors
var front_prices= new Array();
front_prices["None"]=0;
front_prices["One"]=.40;
front_prices["Two"]=1.15;
front_prices["Three"]=1.90;
front_prices["Four"]=2.65;
front_prices["Five"]=3.40;
front_prices["Six"]=4.15;
front_prices["Seven"]=4.90; 

//Set up an associative array 
//The keys represent the back colors
var back_prices= new Array();
back_prices["None"]=0;
back_prices["One"]=.40;
back_prices["Two"]=1.15;
back_prices["Three"]=1.90;
back_prices["Four"]=2.65;
back_prices["Five"]=3.40;
back_prices["Six"]=4.15;
back_prices["Seven"]=4.90; 

//Set up an associative array 
//The keys represent the other colors
var other_prices= new Array();
other_prices["None"]=0;
other_prices["One"]=.40;
other_prices["Two"]=1.15;
other_prices["Three"]=1.90;
other_prices["Four"]=2.65;
other_prices["Five"]=3.40;
other_prices["Six"]=4.15;
other_prices["Seven"]=4.90; 

//The keys represent the front screens
var screens_front_prices= new Array();
screens_front_prices["None"]=0;
screens_front_prices["One"]=15;
screens_front_prices["Two"]=30;
screens_front_prices["Three"]=45;
screens_front_prices["Four"]=60;
screens_front_prices["Five"]=75;
screens_front_prices["Six"]=90;
screens_front_prices["Seven"]=105;

//The keys represent the back screens
var screens_back_prices= new Array();
screens_back_prices["None"]=0;
screens_back_prices["One"]=15;
screens_back_prices["Two"]=30;
screens_back_prices["Three"]=45;
screens_back_prices["Four"]=60;
screens_back_prices["Five"]=75;
screens_back_prices["Six"]=90;
screens_back_prices["Seven"]=105;

//The keys represent the back screens
var screens_other_prices= new Array();
screens_other_prices["None"]=0;
screens_other_prices["One"]=15;
screens_other_prices["Two"]=30;
screens_other_prices["Three"]=45;
screens_other_prices["Four"]=60;
screens_other_prices["Five"]=75;
screens_other_prices["Six"]=90;
screens_other_prices["Seven"]=105;

//Set up an associative array 
//The keys represent the art hours
var art_prices= new Array();
art_prices["One"]=15;
art_prices["Two"]=30;
art_prices["Three"]=45;
art_prices["Four"]=60;
art_prices["Five"]=75;

//Set up an associative array 
//The keys represent the ink color changes
var color_change_prices= new Array();
color_change_prices["None"]=0;
color_change_prices["One"]=5;
color_change_prices["Two"]=10;
color_change_prices["Three"]=15;
color_change_prices["Four"]=20;
color_change_prices["Five"]=25;

//Set up an associative array 
//The keys represent the ink color changes
var pms_color_prices= new Array();
pms_color_prices["None"]=0;
pms_color_prices["One"]=10;
pms_color_prices["Two"]=20;
pms_color_prices["Three"]=30;
pms_color_prices["Four"]=40;
pms_color_prices["Five"]=50;
pms_color_prices["Six"]=60;
pms_color_prices["Seven"]=70;

//This function finds the front price based on the 
//drop down selection
function getfrontPrice()
{
var estimatefrontPrice=0;
//Get a reference to the form id="estimateform"
var theForm = document.forms["estimateform"];
//Get a reference to the select id="front"
var selectedfront = theForm.elements["front"];

//set estimatefront Price equal to value user chose
estimatefrontPrice = front_prices[selectedfront.value];

//finally we return estimatefrontPrice
return estimatefrontPrice;
}

//This function finds the front price based on the 
//drop down selection
function getbackPrice()
{
var estimatebackPrice=0;
//Get a reference to the form id="estimateform"
var theForm = document.forms["estimateform"];
//Get a reference to the select id="front"
var selectedback = theForm.elements["back"];

//set estimatefront Price equal to value user chose
//For example front_prices["Lemon".value] would be equal to 5
estimatebackPrice = back_prices[selectedback.value];

//finally we return estimatefrontPrice
return estimatebackPrice;
}

//This function finds the front price based on the 
//drop down selection
function getotherPrice()
{
var estimateotherPrice=0;
//Get a reference to the form id="estimateform"
var theForm = document.forms["estimateform"];
//Get a reference to the select id="front"
var selectedother = theForm.elements["other"];

//set estimatefront Price equal to value user chose
//For example front_prices["Lemon".value] would be equal to 5
estimateotherPrice = other_prices[selectedother.value];

//finally we return estimatefrontPrice
return estimateotherPrice;
}

//This function finds the front price based on the 
//drop down selection
function getscreens_frontPrice()
{
var estimatescreens_frontPrice=0;
//Get a reference to the form id="estimateform"
var theForm = document.forms["estimateform"];
//Get a reference to the select id="front"
var selectedscreens_front = theForm.elements["screens_front"];

//set estimatefront Price equal to value user chose
estimatescreens_frontPrice = screens_front_prices[selectedscreens_front.value];

//finally we return estimatefrontPrice
return estimatescreens_frontPrice;
}

//This function finds the front price based on the 
//drop down selection
function getscreens_backPrice()
{
var estimatescreens_backPrice=0;
//Get a reference to the form id="estimateform"
var theForm = document.forms["estimateform"];
//Get a reference to the select id="front"
var selectedscreens_back = theForm.elements["screens_back"];

//set estimatefront Price equal to value user chose
estimatescreens_backPrice = screens_back_prices[selectedscreens_back.value];

//finally we return estimatefrontPrice
return estimatescreens_backPrice;
}

//This function finds the back price based on the 
//drop down selection
function getscreens_otherPrice()
{
var estimatescreens_otherPrice=0;
//Get a reference to the form id="estimateform"
var theForm = document.forms["estimateform"];
//Get a reference to the select id="back"
var selectedscreens_other = theForm.elements["screens_other"];

//set estimateback Price equal to value user chose
estimatescreens_otherPrice = screens_other_prices[selectedscreens_other.value];

//finally we return estimatefrontPrice
return estimatescreens_otherPrice;
}


//This function finds the front price based on the 
//drop down selection
function getartPrice()
{
var estimateartPrice=0;
//Get a reference to the form id="estimateform"
var theForm = document.forms["estimateform"];
//Get a reference to the select id="front"
var selectedart = theForm.elements["art"];

//set estimatefront Price equal to value user chose
//For example front_prices["Lemon".value] would be equal to 5
estimateartPrice = art_prices[selectedart.value];

//finally we return estimatefrontPrice
return estimateartPrice;
}

//This function finds the front price based on the 
//drop down selection
function getcolor_changePrice()
{
var estimatecolor_changePrice=0;
//Get a reference to the form id="estimateform"
var theForm = document.forms["estimateform"];
//Get a reference to the select id="front"
var selectedcolor_change = theForm.elements["color_change"];

//set estimatefront Price equal to value user chose
estimatecolor_changePrice = color_change_prices[selectedcolor_change.value];

//finally we return estimatefrontPrice
return estimatecolor_changePrice;
}

//This function finds the front price based on the 
//drop down selection
function getpms_colorPrice()
{
var estimatepms_colorPrice=0;
//Get a reference to the form id="estimateform"
var theForm = document.forms["estimateform"];
//Get a reference to the select id="front"
var selectedpms_color = theForm.elements["pms_color"];

//set estimatefront Price equal to value user chose
estimatepms_colorPrice = pms_color_prices[selectedpms_color.value];

//finally we return estimatefrontPrice
return estimatepms_colorPrice;
}



//rushsPrice() finds the rushs price based on a check box selection
function rushsPrice()
{
var rushPrice=0;
//Get a reference to the form id="estimateform"
var theForm = document.forms["estimateform"];
//Get a reference to the checkbox id="includerushs"
var includerushs = theForm.elements["includerushs"];

//If they checked the box set rushPrice to 5
if(includerushs.checked==true)
{
rushPrice=50;
}
//finally we return the rushPrice
return rushPrice;
}

function less_than_minimumPrice()
{
//This local variable will be used to decide whether or not to charge for the less  
//If the user checked the box this value will be 20
//otherwise it will remain at 0
var less_than_minimumPrice=0;
//Get a refernce to the form id="estimateform"
var theForm = document.forms["estimateform"];
//Get a reference to the checkbox id="includeless_than_minimum"
var includeless_than_minimum = theForm.elements["includeless_than_minimum"];
//If they checked the box set less_than_minimumPrice to 20
if(includeless_than_minimum.checked==true){
less_than_minimumPrice=25;
}
//finally we return the less_than_minimumPrice
return less_than_minimumPrice;
}

function calculateTotal()
{
//Here we get the total price by calling our function
//Each function returns a number so by calling them we add the values they return
var estimatePrice = getfrontPrice() + getbackPrice() + getotherPrice() +  getscreens_frontPrice() + getscreens_backPrice() + getscreens_otherPrice() + getartPrice() + getcolor_changePrice() + getpms_colorPrice() + rushsPrice() + less_than_minimumPrice();

//display the result
var divobj = document.getElementById('totalPrice');
divobj.style.display='block';
divobj.innerHTML = "Total Price For the estimate $"+estimatePrice;

}

function hideTotal()
{
var divobj = document.getElementById('totalPrice');
divobj.style.display='none';
}

{
//If total is 200 for example

var totalPrice = document.getElementById('totalPrice');    
totalPrice.value = "200";
}
4

1 回答 1

0

当您从表单中提取元素时,它们是字符串。您需要将它们转换为数字才能进行数学运算。使用类似的东西:var numVal = parseFloat(formValue)

于 2012-06-01T19:42:26.820 回答