2013-10-12 22 views
0

是否有可能通過此單一基本計算獲得一打結果?我在示例代碼中有兩個輸出文本框;我怎樣才能讓這兩個領域的工作?html如何從單個計算中獲得多個即時結果

<!DOCTYPE html> 

<html lang = "en"> 

<head> 
    <title> multiple results calculation </title> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/> 
    <link rel="style" href="css/main.css" type"text/css"/> 

    <!-- I need multiple results from single calculation! 

    <script type="text/javascript"> 
     function sum() 
     { 
     var width = document.multiple results.width.value; 
     var height = document.multiple results.value; 
     var sum = parseInt(width) * parseInt(height) /144; 
     document.getElementById('Calculate').value = sum; 

     document.getElementById("results1").readOnly=true; 
     document.getElementById("results2").readOnly=true; 


     var result1= $1.99; 
     var result2= $2.99; 

     document.getElementById('Calculate').value = sum * result1; 
     document.getElementById('Calculate').value = sum * result2; 

     } 
    </script>  
    --> 

</head> 
    <body> 

    <div> 
     <H2> Multiple instant results from single calculation</h2> 
     <p> the goal eventually is to have about a dozen results from this single calculation 
    </div> 

     <form name="multiple results"> 

      <label for="width"> Width: </label> 
      <input type="number" <id="width" maxlength="4" size="10" value=""/> 

      <label for="height"> Height: </label> 
      <input type="number" <id="height" maxlength="4" size="10" value=""/> 

      <input type="button" name="button" value="Calculate" onClick="sum"/> 

      <div> 

      <label for="result1"> Result1: $ </label> 
      <input type="number" id="result1" name="result1"/> 

      <label for="result2"> Result2: $ </label> 
      <input type="number" id="result2" name="result2"/>  
      </div> 

     </form> 
    </body> 
</html> 
+0

只是爲了澄清:你是說你想有要在12個不同的輸入字段顯示12分的成績,當你運行'總和()'? – xaisoft

+0

爲什麼一次計算會給出一打(不同的)結果? –

+0

@DavidThomas - 我想他想要12個不同的局部變量,每個局部變量在乘以總和時會產生不同的結果,然後這些值將被放入12個不同的輸入中。 – xaisoft

回答

0

我找到了解決方案通過去除所述第一的document.getElementById(「計算」)。值=總和;,改變剩餘的getElementById的和輸入類型的導致和RESULT2還添加缺少的值=「」輸入,沒有必要的,但重命名編號的幫我

相關問題