我不能得到下面的腳本工作,我真的不明白爲什麼。應該正常工作爲什麼我的Javascript價格計算器不工作?
每個變量都會計入,但是沒有顯示價格?
的HTML是這個頁面上可見:http://virkfilm.dk/prisb/
var cake_prices = new Array();
cake_prices["filmtype1"]=5000;
cake_prices["filmtype2"]=5000;
cake_prices["filmtype3"]=5000;
var filling_prices= new Array();
filling_prices["Canon"]=0;
filling_prices["Blackmagic"]=2000;
filling_prices["Red"]=5000;
var rejse_prices= new Array();
rejse_prices["storkbh"]=0;
rejse_prices["sjaelland"]=300;
rejse_prices["fyn"]=600;
rejse_prices["jylland"]=1000;
var dage_prices= new Array();
dage_prices["1"]=0;
dage_prices["2"]=3500;
dage_prices["3"]=7000;
var speak_prices= new Array();
speak_prices["nospeak"]=0;
speak_prices["dansk"]=1600;
speak_prices["engelsk"]=1600;
function getCakeSizePrice()
{
var cakeSizePrice=0;
var theForm = document.forms["prisberegner"];
var selectedCake = theForm.elements["selectedcake"];
for(var i = 0; i < selectedCake.length; i++)
{
if(selectedCake[i].checked)
{
cakeSizePrice = cake_prices[selectedCake[i].value];
break;
}
}
return cakeSizePrice;
}
function getFillingPrice()
{
var cakeFillingPrice=0;
var theForm = document.forms["prisberegner"];
var selectedFilling = theForm.elements["filling"];
cakeFillingPrice = filling_prices[selectedFilling.value];
return cakeFillingPrice;
}
function getRejsePrice()
{
var RejsePrice=0;
var theForm = document.forms["prisberegner"];
var selectedRejse = theForm.elements["rejse"];
RejsePrice = rejse_prices[selectedRejse.value];
return RejsePrice;
}
function getDagePrice()
{
var DagePrice=0;
var theForm = document.forms["prisberegner"];
var selectedDage = theForm.elements["dage"];
DagePrice = dage_prices[selectedDage.value];
return DagePrice;
}
function getSpeakPrice()
{
var SpeakPrice=0;
var theForm = document.forms["prisberegner"];
var selectedDage = theForm.elements["speak"];
SpeakPrice = speak_prices[selectedSpeak.value];
return SpeakPrice;
}
function lydPrice()
{
var lydPrice=0;
var theForm = document.forms["prisberegner"];
var lyd = theForm.elements["lyd"];
if(lyd.checked==true)
{
lydPrice=1500;
}
return lydPrice;
}
function speakoverPrice()
{
var speakoverPrice=0;
var theForm = document.forms["prisberegner"];
var speakover = theForm.elements["speakover"];
if(speakover.checked==true)
{
speakoverPrice=1600;
}
return speakoverPrice;
}
function uspeakPrice()
{
var uspeakPrice=0;
var theForm = document.forms["prisberegner"];
var uspeak = theForm.elements["uspeak"];
if(uspeak.checked==true)
{
uspeakPrice=1000;
}
return uspeakPrice;
}
function musikPrice()
{
var musikPrice=0;
var theForm = document.forms["prisberegner"];
var musik = theForm.elements["musik"];
if(musik.checked==true){
musikPrice=1200;
}
return musikPrice;
}
function storyPrice()
{
var musikPrice=0;
var theForm = document.forms["prisberegner"];
var story = theForm.elements["story"];
if(story.checked==true){
storyPrice=1000;
}
return storyPrice;
}
function includecandlesPrice()
{
var includecandlesPrice=0;
var theForm = document.forms["prisberegner"];
var includecandles = theForm.elements["includecandles"];
if(includecandles.checked==true){
includecandlesPrice=1000;
}
return includecandlesPrice;
}
function calculateTotal()
{
var cakePrice = getCakeSizePrice() + getSpeakPrice() + getFillingPrice() + getRejsePrice() + getDagPrice() + lydPrice() + speakoverPrice() + uspeakPrice() + musikPrice() + storyPrice() + includecandlesPrice();
var divobj = document.getElementById('totalPrice');
divobj.style.display='block';
divobj.innerHTML = "Total Price For the Cake $"+cakePrice;
}
function hideTotal()
{
var divobj = document.getElementById('totalPrice');
divobj.style.display='none';
}
我應該感謝javascript-coder.com對於我試圖適應腳本模板。
1)不要使用'new Array()';使用'[]'2)如果你需要的是對象,不要創建數組;使用'{}'4)如果你的對象是靜態的,把它們初始化爲對象文本的一部分5)'== true'通常是毫無意義的,但總是令人困惑6)控制檯中的任何錯誤? – Ryan
打開你的瀏覽器的控制檯,你會看到'未捕獲的ReferenceError:selectedSpeak未定義(索引):275' –
Ctrl-Shift-J在Chrome上打開瀏覽器控制檯。 –