javascript - 为什么我的 Javascript 价格计算器不起作用?

标签 javascript html

我无法让下面的脚本工作,我真的不明白为什么。应该可以正常工作

每个变量都被考虑在内,但没有显示价格?

可在此页面查看 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 为我尝试改编的脚本模板。

最佳答案

你在哪里

var selectedDage = theForm.elements["speak"];

应该是

var selectedSpeak = theForm.elements["speak"];

否则 selectedSpeak 未在任何地方定义。

关于javascript - 为什么我的 Javascript 价格计算器不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19671677/

相关文章:

javascript - 给定文件扩展名,如何为 Ace Editor 自动选择 "mode"

javascript - 绘制元素边框(动画)

php - 要求用户使用 YYYY-MM-DD 格式输入日期

javascript - Google maps Places API V3 自动完成 - 在输入时选择第一个选项(并保持原样)

javascript - 未捕获的 TypeError : lineChart. Line 不是 Chart.js 中的函数

javascript - 全局变量 Ionic 2

javascript - 在此 Windows 小工具中查找导致内存泄漏的原因

javascript - 根据自己已有的内容替换header标签的内容

html - 当图片需要覆盖页面的整个部分时,图片只覆盖正文的一小部分

html - Foundation 4 选项卡部分可以在 Reveal 中显示吗?