我正在尝试使用javascript提交表单。但它始终错误为“无法调用未定义的方法提交”我在表单上的名称上交叉检查但是它没有用,我写了一个示例HTML来检查这种方法是否有效并且工作正常。请帮我解决这个问题。
我的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");
}
答案 0 :(得分:2)
你的问题是你没有一个名为ashutosh的表格。你有一个名为ashutosh的id的表单,所以要么使用:
document.getElementById('ashutosh').submit();
或者将您的HTML代码更改为:
<form name="ashutosh" method="POST" action="symptoms" >
答案 1 :(得分:0)
它应该是这样的:
document.ashutosh.submit();