2015-10-14 45 views
0

我試圖從窗體中檢索這個值,但它沒有返回任何東西。這應該如何解決?任何人都可以將我指向正確的方向嗎?爲什麼javascript無法獲得表單值?

function checkForm() 
{ 
    numrows = document.theform.numrows.value; 
    if(numrows == -1) 
    { 
    alert("You have not chosen any options yet"); 
    return false; 
    } 

    emailcheckcount = 0; 
    for(i=0; i<=numrows; i++) 
    { 
     var recid = document.theform.recid'+i+'.value; //why is this failing to get value here? 
     alert("Test" + recid); 
     return false; 
    } 
} 
+1

該行的語法document.theform.recid '+ I +' 值不正確。您是否檢查過瀏覽器日誌以獲取任何錯誤消息。 考慮添加一個HTML表單的代碼片段,這個函數被調用,所以有人想要回答可能有更多的信息。另請註明您是否收到警報。如果您使用的是Firefox/Chrome瀏覽器,請嘗試使用console.log來打印一些調試消息。 – vvs

回答

5

請儘量使用數組來存取權限值:

var recid = document.theform.recid[i].value; 
相關問題