2014-04-01 56 views
0

我想將兩個表單放在一個頁面上,但只有一個主要顯示區域可以進行選擇。我的網頁看起來是這樣的:使用onchange在第二個字段中輸入數據javascript

序列ID ---選擇處理器---選擇審閱

1 ------------------- A- ----------------------- B ---------------動作按鈕

2 ---- ---------------甲------------------------乙--------- ------動作按鈕

3 ------------------- A ----------------- ------- B ---------------動作按鈕

其中A和B是用戶可以選擇的淹沒列表。

然後,在頁面的單獨部分和單獨的表單中,上面選擇的A和B將填充到單獨的文本字段中。問題在於這兩種形式是如何處理的。上面的「動作按鈕」不使用A和B下拉信息AT ALL。但爲了使顯示更加簡潔,我不想讓用戶滾動到頁面的各個部分進行不同的操作。太混亂。

這是踢球者。序列中的總數將根據形式而有所不同。所以,我需要爲這些字段創建一個數組。我知道,是不是做多大意義,所以我在這裏是我的代碼:

<script type="text/javascript"> 
function myFunction() { 
document.proc[1].value = f.processor[1].value; 
      document.write.getElementById("proc[1]").value; 
      document.rev[1].value = f.reviewer[1].value; 
      document.write.getElementById("rev[1]").value; 
      document.proc[2].value = f.processor[2].value; 
      document.write.getElementById("proc[2]").value; 
      document.rev[2].value = f.reviewer[2].value; 
      document.write.getElementById("rev[2]").value; 
      document.proc[3].value = f.processor[3].value; 
      document.write.getElementById("proc[3]").value; 
      document.rev[3].value = f.reviewer[3].value; 
      document.write.getElementById("rev[3]").value; 
     } 
</script> 
<form id="form" action="thispage.php" method="post"> 
    <select name="processor[1]" onchange="myFunction(this.document)" id="processor[1]"> 
     <option value="0">--Please select from the list...</option> 
     <option value="A">A</option> 
     <option value="B">B</option> 
     <option value="C">C</option> 
    </select> 
    <select name="reviewer[1]" onchange="myFunction(this.document)" id="reviewer[1]"> 
     <option value="0">--Please select from the list...</option> 
     <option value="A">A</option> 
     <option value="B">B</option> 
     <option value="C">C</option> 
    </select> 
    <select name="processor[2]" onchange="myFunction(this.document)" id="processor[2]"> 
     <option value="0">--Please select from the list...</option> 
     <option value="A">A</option> 
     <option value="B">B</option> 
     <option value="C">C</option> 
    </select> 
    <select name="reviewer[2]" onchange="myFunction(this.document)" id="reviewer[2]"> 
     <option value="0">--Please select from the list...</option> 
     <option value="A">A</option> 
     <option value="B">B</option> 
     <option value="C">C</option> 
    </select> 
    <select name="processor[3" onchange="myFunction(this.document)" id="processor[3]"> 
     <option value="0">--Please select from the list...</option> 
     <option value="A">A</option> 
     <option value="B">B</option> 
     <option value="C">C</option> 
    </select> 
    <select name="reviewer[3]" onchange="myFunction(this.document)" id="reviewer[3]"> 
     <option value="0">--Please select from the list...</option> 
     <option value="A">A</option> 
     <option value="B">B</option> 
     <option value="C">C</option> 
    </select> 
<input type="submit" name="action" value="Action Button"> 
</form> 
<form id="newForm" action="thisform.php" method="post"> 
    <input type="text" name="proc[1]" id="proc[1]"> 
    <input type="text" name="rev[1]" id="rev[1]"> 
    <input type="text" name="proc[2]" id="proc[2]"> 
    <input type="text" name="rev[2]" id="rev[2]"> 
    <input type="text" name="proc[3]" id="proc[3]"> 
    <input type="text" name="rev[3]" id="rev[3]"> 
</form> 

當我做出選擇,數據不進入的newForm,這是我想發生什麼文本字段。

任何人可以提供的建議將不勝感激。

回答

0

回答爲什麼選擇未被傳送: 有<input type="text" name="proc[1]" id="proc[1]">不允許您通過document.proc[1]來引用它。文檔對象模型並不那麼神奇。其他說明: 該代碼還有很多其他問題, this.documentdocument.write.getElementById(...).value。您應該花一些時間學習JavaScript和文檔對象模型,並找到適合此應用程序的方法。

+0

感謝您花時間查看代碼。談到JavaScript時,我知道我是新手。我會進一步研究。 – Combe

相關問題