0

使用计算器模板,我编辑并添加了我自己的部分。

我希望用户能够选择纸张尺寸、张数和纸张重量。

最终计算为

(张数 * 纸张重量) * 纸张尺寸

我无法正确添加纸张重量部分。(代码中命名为gsm)

    <form action="" id="weightform" onsubmit="return false;">
    <div>

            <label class='radiolabel'><input type="radio"  name="selectedsheets" value="A3" onclick="calculateTotal()" />A3</label><br/>
            <label class='radiolabel'><input type="radio"  name="selectedsheets" value="A4" onclick="calculateTotal()" />A4</label><br/>
            <label class='radiolabel'><input type="radio"  name="selectedsheets" value="A5" onclick="calculateTotal()" />A5</label><br/>

            <select id="sheets" name='sheets' onchange="calculateTotal()">
            <option value="None">Select Sheets</option>
            <option value="5Sheets">5 Sheets</option>
            <option value="10Sheets">10 Sheets</option>
            </select>

            <label class='radiolabel'><input type="radio"  name="selectedgsm" value="100"/>110</label><br/>
            <label class='radiolabel'><input type="radio"  name="selectedgsm" value="110"/>120</label><br/>
            <label class='radiolabel'><input type="radio"  name="selectedgsm" value="120"/>130</label><br/>

            <div id="totalWeight"></div>

    </div>  
   </form>

代码

             //Set up an associative array - paper_size
             var paper_size = new Array();
             paper_size["A3"]=2;
             paper_size["A4"]=1;
             paper_size["A5"]=0.5;

             //Set up an associative array - sheet_amount
             var sheet_amount= new Array();
             sheet_amount["None"]=0;
             sheet_amount["5Sheets"]=5;
             sheet_amount["10Sheets"]=10;

             //Set up an associative array - gsm_amount
             var gsm_amount= new Array();
             gsm_amount["100"]=100;
             gsm_amount["110"]=110;
             gsm_amount["120"]=120;
             gsm_amount["130"]=130;
             gsm_amount["140"]=140;

            function getpaperchoice()
            {  
                var paperchoice=0;
                var theForm = document.forms["weightform"];
                var selectedsheets = theForm.elements["selectedsheets"];
                for(var i = 0; i < selectedsheets.length; i++)
                {
                    if(selectedsheets[i].checked)
                    {

                        paperchoice = paper_size[selectedsheets[i].value];
                        break;
                    }
                }

                return paperchoice;
            }

            function getsheetchoice()
            {
                var sheetchoice=0;
                var theForm = document.forms["weightform"];
                 var selectedsheets = theForm.elements["sheets"];

                sheetchoice = sheet_amount[selectedsheets.value];

                return sheetchoice;
            }

            function getgsmchoice()
            {
                var gsmchoice=0;
                var theForm = document.forms["weightform"];
                var selectedgsm = theForm.elements["selectedgsm"];

                gsmchoice = gsm_amount[selectedgsm.value];

                return gsmchoice;
            }

            function calculateTotal()
            {
                var TotalWeight = (getsheetchoice() * getgsmchoice()) * getpaperchoice();

                //display the result
                var divobj = document.getElementById('totalWeight');
                divobj.style.display='block';
                divobj.innerHTML = "Total Weight "+TotalWeight;

            }

请提供任何帮助和建议!

Gsm 按照建议更改为选定的 gsm,到了一半但问题没有解决......

4

0 回答 0