I am trying to submit a form using javascript . But its always error out as "Cannot call method submit of undefined " i crosschecked on the name on the form but it didnot worked , I wrote one sample HTML to just check if this approach works and it was working fine . Please help me out on this .
my 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>
my 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");
}
asked Oct 17, 2011 at 9:46
bhalkian
4995 gold badges15 silver badges32 bronze badges
2 Answers 2
Your problem is that you don't have a form called ashutosh. You have a form with an id called ashutosh, so either use:
document.getElementById('ashutosh').submit();
Or change your HTML code to:
<form name="ashutosh" method="POST" action="symptoms" >
answered Oct 17, 2011 at 9:52
Some Guy
16.2k10 gold badges61 silver badges68 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
bhalkian
can anyone tell me why doesnot it work with <html:form > tag ??
Some Guy
I don't know much about it, sorry. Is the form displaying correctly when you use that library?
It should be something like this:
document.ashutosh.submit();
answered Oct 17, 2011 at 9:57
Amit Merchant
1111 gold badge1 silver badge10 bronze badges
1 Comment
Álvaro González
Relying in the browser providing global variables is so 1997... :)
lang-js