2013-10-25 30 views
0

HTML表單(outputed直通PHP)無法讀取未定義的屬性 '元素' - 在JS控制檯

$retVal .= "<form id= 'importSampleDataForm' name = 'importSampleDataForm' onsubmit = \"return false\" >\n"; 

    // Form content edited out; it contains several dozen checkboxes 

$retVal .= sprintf("<input type='button' class='wn_button' onclick='SaveMotorSkills();' value='Import Selected'>\n"); 
$retVal .= "</form>\n"; 

的JavaScript/AJAX

​​

見 「線與錯誤上面」 在for循環。 JS控制檯說

Uncaught TypeError: Cannot read property 'elements' of undefined

我已經看過這段代碼這麼多我的眼睛不能再忍受了。有沒有人看到我不喜歡的東西?如果需要,我可以添加更多的代碼。

+0

您是否正在從頁腳運行'SaveMotorSkills'函數,或者頁/ html在屏幕上?你應該。 –

+0

它從一個單獨的'.js'文檔運行,並且該表單已經顯示在屏幕上。當你點擊窗體底部的按鈕時,這是它運行的時候。 – KickingLettuce

回答

4

嘗試

document.getElementById('importSampleDataForm').elements.length 

此外,nested forms are not allowed,這樣也需要解決。

+0

,這給我一個新的錯誤:'未捕獲的類型錯誤:無法讀取null的屬性'元素' – KickingLettuce

+0

@KickingLettuce,什麼時候SaveMotorSkills運行?新的錯誤仍然在同一行上,對嗎? – Patrick

+0

我在上面的評論中添加了這個答案。 – KickingLettuce

相關問題