2015-06-03 27 views
1

我想在其中提交<form><table>。如何使用默認操作提交<form>?使用<select>標籤,我可以使用onchange javascript函數提交表單。我認爲onclick="this.form.submit"裏面的<td>標籤會解決,但螢火蟲表示有錯誤:TypeError: this.form is undefined內嵌td標記的javascript onlick

有什麼不對?你指的是在的onclick功能

<div class="report"> 
    <form method="post" name="status_students"> 
    <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
     <tr> 
     <td class="tdreport">Active</td> 
     <td class="tdreport">Unstable</td> 
     <td class="tdreport">Inactive</td> 
     </tr> 
     <tr> 
     <td class="active" name="students_actives" value="actives" onclick="this.form.submit()"> 
      <?php 
      if ($this->siteCenterSelected == "All") { 
      echo count($this->usersStatus['verde']); 
      } else { 
      echo count($this->usersStatusSiteCenter['verde']); 
      } 
      ?> 
     </td> 
     <td class="unstable"><?php 
      if ($this->siteCenterSelected == "All") { 
      echo count($this->usersStatus['amarelo']); 
      } else { 
      echo count($this->usersStatusSiteCenter['amarelo']); 
      } 
      ?> 
     </td> 
     <td class="inactive"><?php 
      if ($this->siteCenterSelected == "All") { 
      echo count($this->usersStatus['vermelho']); 
      } else { 
      echo count($this->usersStatusSiteCenter['vermelho']); 
      } 
      ?> 
     </td> 
     </tr> 
    </table> 
    </form> 
</div> 
+0

在你的場景中'this'是指td元素,一個骯髒的解決方案是使用'.parent' - >'this.parent.parent.parent'在dom中提升。你也可以通過他的名字找到你的表格。 'document.status_students' – Cyrbil

+2

嘗試'document.status_students.submit()'! –

回答

1

this對象是點擊td,而不是整個文件。你可能想用這個來代替:

onclick="document.forms[0].submit()" 

但的確,你最好用它的ID來引用表單。

+0

請注意,如果您有多個表單,請更改索引,因爲'[0]'表示第一個表單元素。 – kosmos

+0

非常感謝陶。實際上,我在'td'標籤內創建了一個'onclick'的函數,用'document.getElementById(「status_students」)。submit()'提交表單。 – Caco