Javascript意外行为2问题(数学错误&未显示简单结果)

Javascript意外行为2问题(数学错误&未显示简单结果),javascript,html,Javascript,Html,请帮帮我,从我对javascript编码非常精通的代码中你可以看出,我已经成功地将其组合在一起,我非常接近于让它发挥我所需要的功能,但有几个小问题我无法解决 代码发布在下面,但要复制我遇到的问题,请执行以下操作 要复制问题1 去 按底部的“显示/隐藏计算器”链接 在顶部框宽度和高度中输入一些测试编号 请注意,输入框的第10步中的数字 计算是错误的 按下go按钮,注意步骤10中的数字现在为 对的 为什么一开始是错的 问题2。。 它应该在页面顶部以纯文本的形式显示步骤10的结果,但它根本没有显示任何

请帮帮我,从我对javascript编码非常精通的代码中你可以看出,我已经成功地将其组合在一起,我非常接近于让它发挥我所需要的功能,但有几个小问题我无法解决

代码发布在下面,但要复制我遇到的问题,请执行以下操作

要复制问题1

去 按底部的“显示/隐藏计算器”链接 在顶部框宽度和高度中输入一些测试编号 请注意,输入框的第10步中的数字 计算是错误的 按下go按钮,注意步骤10中的数字现在为 对的 为什么一开始是错的

问题2。。 它应该在页面顶部以纯文本的形式显示步骤10的结果,但它根本没有显示任何内容

代码

<head>
<script type="text/javascript"><!--

function updatesum()
{
    if (+document.form.inputwidth.value > 1280) 
    {
        alert('Maximum width is 1280mm, please reduce');
    }
    else {
        updatesum2()
    }
}
function updatesum2()

{
    if (+document.form.inputwidth.value < 20) 
    {
        alert('Minimum width is 20mm, please increase');
    }
    else {
        updatesum5()
    }
}

function updatesum3()
{
    if (+document.form.inputheight.value > 685) 
    {
        alert('Maximum height is 685mm, please reduce');
    }
    else {
        updatesum4()
    }
}
function updatesum4()

{
    if (+document.form.inputheight.value < 20) 
    {
        alert('Minimum height is 20mm, please increase');
    }
    else {
        updatesum5()
    }
}

function updatesum5()
{
    if (+document.form.switchedstickeramount.value > +document.form.rawstickeramount.value) 
    {
        document.form.biggestresult.value = +document.form.switchedstickeramount.value;
    }
    else {
        document.form.biggestresult.value = +document.form.rawstickeramount.value;
    }
updatesum6()
}
function updatesum6()
{
document.form.neww.value = +document.form.inputwidth.value + +document.form.bleed.value;
document.form.newh.value = +document.form.inputheight.value + +document.form.bleed.value;
document.form.stickersupsheet.value = Math.floor(+document.form.nsheetw.value / +document.form.neww.value);
document.form.stickersacsheet.value = Math.floor(+document.form.nsheeth.value / +document.form.newh.value);
document.form.nsheetw.value = +document.form.sheetw.value - +document.form.sheetbleed.value;
document.form.nsheeth.value = +document.form.sheeth.value - +document.form.sheetbleed.value;
document.form.stickersupsheetsw.value = Math.floor(+document.form.nsheetw.value / +document.form.newh.value);
document.form.stickersacsheetsw.value = Math.floor(+document.form.nsheeth.value / +document.form.neww.value);
document.form.rawstickeramount.value = document.form.stickersupsheet.value * document.form.stickersacsheet.value;
document.form.switchedstickeramount.value = document.form.stickersupsheetsw.value * document.form.stickersacsheetsw.value;
document.form.resultraw.value = document.form.sheetarea.value / document.form.stickerarea.value;
updatesum7()    
}

function updatesum7()
{
    if (+document.form.switchedstickeramount.value > +document.form.rawstickeramount.value) 
    {
       document.getElementById("sywg").innerHTML = +document.form.switchedstickeramount.value;
    }
    else {
       document.getElementById("sywg").innerHTML = +document.form.rawstickeramount.value;
    }    
}


function ClearForm(){
    document.form.reset();
}

//---></script>
<link rel="shortcut icon" type="image/x-icon" href="images/calcicon.ico">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<!-- iPad Setup -->
    <meta name="viewport" content="minimum-scale=1.0, maximum-scale=1.0,
    width=device-width, user-scalable=no">
    <script src="//code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript">
<!--
    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }
//-->
</script>
</head>
<body  onload="ClearForm()">
<form name="form">
<div><b>Stickers Per <i>1300x700mm Sheet</i> Calculator.</b></div><br/>
<small>Enter dimensions for a single sticker<i> (mm)</i>:</small><br>
<small>WIDTH <small>(Max 1280 / Min 20)</small></small> &nbsp;&nbsp;&nbsp;<small>HEIGHT <small>(Max 685 / Min 20)</small></small><br />
<input name="inputwidth" id="inputwidth" onChange="updatesum()" class="form-field" type="number" max="1280" min="20" step="1" /> x <input name="inputheight" id="inputheight" onChange="updatesum3()" class="form-field" type="number" max="685" min="20" step="1" />mm <button type="button" class="submit-button"  onclick="updatesum3()">GO</button><br/>
<small><br>Amount of stickers you'll get..</small>
<br/>
<big><span id="sywg" name="resultplain"></span></big> Stickers <small><small>(Approx)</small></small>


<!---Calculations BOX START--->
 <span id="calcs" style="display:none; border: 1px solid #000000; padding:10px; margin-top:5px;">Calculations..<br />
<b><small><small><small>1) Individual sticker bleed +</small></small></small></b><input name="bleed" value="10" onChange="updatesum()" class="form-field" type="number" />mm <small><i>(Editable)</i></small>
 <hr>
 <b><small><small><small>2) New individual sticker size with bleed added =</small></small></small></b><input name="neww" readonly onChange="updatesum()" class="form-field" type="number" /> x <input name="newh" readonly onChange="updatesum()" class="form-field" type="number" />mm <small><i>(Read Only)</i></small>
 <hr>
  <b><small><small><small>3) Sheet Size =</small></small></small></b><input name="sheetw" value="1300" onChange="updatesum()" class="form-field" type="number" /> x <input name="sheeth" value="700" onChange="updatesum()" class="form-field" type="number" />mm  <small><i>(Editable)</i></small>
 <hr>
 <b><small><small><small>4) Outer sheet bleed =</small></small></small></b><input name="sheetbleed" value="5" onChange="updatesum()" class="form-field" type="number" />mm <small><i>(Editable)</i></small>
 <hr>
 <b><small><small><small>5) Sheet Size Minus Bleed =</small></small></small></b><input name="nsheetw" readonly onChange="updatesum()" class="form-field" type="number" /> x <input name="nsheeth" readonly onChange="updatesum()" class="form-field" type="number" />mm <small><i>(Read Only)</i></small>
 <hr>
 <b><small><small><small>6a) Amount of stickers that fit up the sheet </small></small><small><small><small>(rounded down to whole sticker)</small></small></small></small></small></small> =</b><input name="stickersupsheet" onChange="updatesum()" readonly class="form-field" type="number" /> <small><i>(Read Only)</i></small>
 <hr>
 <b><small><small><small>6b) Amount of stickers that fit across the sheet </small></small><small><small><small>(rounded down to whole sticker)</small></small></small></small></small></small> =</b><input name="stickersacsheet" onChange="updatesum()" readonly class="form-field" type="number" /> <small><i>(Read Only)</i></small>
 <hr>
  <b><small><small><small>7) Amount of stickers as user inputted =</small></small></small></b><input name="rawstickeramount" onChange="updatesum()" readonly class="form-field" type="number" /> <small><i>(Read Only)</i></small>
 <hr>
  <b><small><small><small>8a) Amount of stickers that fit up the sheet (if w&h switched)</small></small><small><small><small>(rounded down to whole sticker)</small></small></small></small></small></small> =</b><input name="stickersupsheetsw" onChange="updatesum()" readonly class="form-field" type="number" /> <small><i>(Read Only)</i></small>
 <hr>
   <b><small><small><small>8b) Amount of stickers that fit across the sheet (if w&h switched)</small></small><small><small><small>(rounded down to whole sticker)</small></small></small></small></small></small> =</b><input name="stickersacsheetsw" onChange="updatesum()" readonly class="form-field" type="number" /> <small><i>(Read Only)</i></small>
 <hr>
   <b><small><small><small>9) Amount of stickers if switch =</small></small></small></b><input name="switchedstickeramount" onChange="updatesum()" readonly class="form-field" type="number" /> <small><i>(Read Only)</i></small>
 <hr>
 <b><small><small><small>10) Check if portrait or landscape would give more stickers and show most =</small></small></small></b><input name="biggestresult" onChange="updatesum()" readonly class="form-field" type="number" /> <small><i>(Read Only)</i></small>
 <hr>
</span><!---Calculations SIZES BOX END--->
<div><br>
<button type="reset" class="submit-button"  value="Reset">Clear All</button><br><br></div>
<small><small><small><a href="#" onclick="toggle_visibility('calcs');">Show/Hide Calculations</a></small></small></small>
</form>


</body>

如果在浏览器中打开“开发人员工具”窗口并检查控制台窗口,您将看到一个问题:

stickersv2.php:71 Uncaught TypeError: Cannot read property 'value' of undefined
看起来您指的是document.form.stickerarea.value,但浏览器告诉您找不到document.form.stickerarea


我建议您也在开发人员工具中使用JavaScript调试器来找出计算中的问题所在。

这是否回答了您的问题?非常好,感谢您为我指明了正确的方向,并提供了有关控制台和JavaScript调试器的有用提示,现在一切正常。再次感谢:-