2011-10-17 112 views
1

我正在嘗試使用javascript提交表單。但它始終錯誤爲「無法調用未定義的方法提交」我對錶單上的名稱進行了交叉檢查,但它沒有奏效,我寫了一個示例HTML來檢查這種方法是否工作正常。請幫我解決這個問題。使用javascript提交表單

我的JSP:

<div id="Symptoms" style="display:none;"> 
<html:form id="ashutosh" method="POST" action="symptoms" > 
<p></p> 
<p>Enter/Choose ailment : 

<html:select id="diselc" name="AuthoringForm" property="disease_name" size="1" onchange="javascript:formsubmit(this.formName);" > 
<option selected="selected"> </option> 
<option>Malaria</option> 
<option>High Fever</option> 
<option>Cholera</option> 
<option>Diarrhoea</option> 
</html:select></p> 
<p>Choose ailment classification : 
<html:select id="diselchild" name="AuthoringForm" property="diesclassifiaction" > 
<option>High</option> 
<option>Medium</option> 
<option>Low</option> 
</html:select> 



<fieldset style="width: 381px; height: 126px; padding: 2"> 
<legend align="left"></legend> 
Tick off patient context : 
<html:radio value="Men" name="AuthoringForm" property="patient_context" disabled="false"/> 
Men 
<html:radio value="Womwen" name="AuthoringForm" property="patient_context" disabled="false"/> 
Women 
<p> 
<html:radio value="Child" name="AuthoringForm" property="patient_context" disabled="false"/> 
Child 
<html:radio value="Al" name="AuthoringForm" property="patient_context" disabled="false"/> 
All 
</fieldset> 
<p>Enter Pre Conditions</p> 
<p><html:textarea rows="2" name="AuthoringForm" cols="20" property="patient_precondition" ></html:textarea> 
<p>Must Have Symptoms : 
May Have Symptoms :</p> 
<p><html:textarea rows="2" name="AuthoringForm" cols="20" property="must_have_symptoms"></html:textarea> 
<!-- <input type="submit" value="Submit" name="B2">--> 
<html:textarea rows="2" name="AuthoringForm" cols="20" property="may_have_symptoms"></html:textarea> 
<input type="submit" value="Submit" name="symptomsButton"><input type="reset" value="Reset" onclick="clear_form_elements(this.form);"></p> 
</html:form> 
</div> 

我的javascript:

function formsubmit(value){ 
alert("i am just above the form submission"+value); 
document.forms["ashutosh"].submit(); 
alert("i am just after the form submission"); 
} 

回答

2

你的問題是,你沒有一個叫Ashutosh說形式。你有一個ID叫Ashutosh說一種形式,所以無論使用:

document.getElementById('ashutosh').submit(); 

或更改HTML代碼:

<form name="ashutosh" method="POST" action="symptoms" > 
+0

誰能告訴我爲什麼不能用標籤? – bhalkian

+0

我不知道那個標籤是關於什麼的。當我嘗試它時,它甚至不能在普通的HTML頁面上工作。它是JSP特定的還是其他的? 編輯:通過代碼片段[這裏](http://www.jsptut.com/Tags.jsp),我想你只是誤解了。 HTML標籤不像JSP標籤那樣使用HTML前綴。 –

+0

這些是struts標籤庫 – bhalkian

0

應該是這樣的:

文件。 ashutosh.submit();

+4

依賴於瀏覽器提供的全局變量是如此1997年:) –