遗漏的类型错误:无法设置的未定义的属性“值” - JS

问题描述:

enter image description here遗漏的类型错误:无法设置的未定义的属性“值” - JS

好家伙,一个人可以帮我如何解决这个问题?我试图找出它3个小时,但仍然无法修复。它在事件的第一次尝试或第一次射击中工作,但如果事件再次触发,则不再有效。

这是剧本。

<script type="text/javascript" language="Javascript"> 
    var sum=0; 
    function OnChange(value){ 

    price = document.getElementById('select1').value;  
    quantity = document.getElementById('select2').value; 
     sum = price * quantity; 

    document.frmOne.txtDisplay.value = sum; 
    } 
</script> 
<SCRIPT language=Javascript> 
     <!-- 
     function isNumberKey(evt) 
     { 
     var charCode = (evt.which) ? evt.which : event.keyCode 
     if (charCode > 31 && (charCode < 48 || charCode > 57)) 
      return false; 

     return true; 
     } 
     //--> 
    </SCRIPT> 

这里的FORM

<form NAME = "frmOne" action="initiateorder.php" method="post" enctype="multipart/form-data"> 
    <input type="hidden" name="transnum" value="<?php echo $_GET['trnasnum'] ?>" /> 
    <INPUT TYPE = "Text" name = "select1" size = "35" id="select1" value ="<?php echo $price ?>" style="display:none;"> 
    <INPUT TYPE = "Text" name = "pname" size = "35" value ="<?php echo $name ?>" style="display:none;"> 
    <br> 
    <span style="font-size:11px; font-family:Arial, Helvetica, sans-serif; text-align:left; line-height:17px;color:#000000;">Quantity : </span> 
    <input type="text" name="select2" id="select2" onkeyup="OnChange(this.value)" onKeyPress="return isNumberKey(event)" style="width:60px;" /> 

    <span style="color:#B80000; font-size:16px; font-weight:bold; font-family:Arial, Helvetica, sans-serif;">=</span> 
    <INPUT TYPE = "Text" name = "txtDisplay" size = "35" value ="<?php echo $price ?>" style="border:#999999 solid 1px; background-color:#FFF; width:100px; height:20px;" readonly> 
</form> 

尝试document.getElementsByName("txtDisplay")[0].value = sum代替document.frmOne.txtDisplay.value = sum;

+0

为什么会变成这样的工作时,后者将无法正常工作? – Adam

+0

它的工作!你能解释为什么吗? – nethken