Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error when submitting a form

Status
Not open for further replies.

meenu24

Programmer
May 5, 2006
37
US
The code is as given below. WHen I submit this form I get a error alert " 'document.form2' is null or not an object". I am confused of why this the error. Any suggestions welcome. Thanks for your time.
<script>
function sub2()
{
try
{
document.form2.submit();
}
catch(err)
{
al = err.description;
alert(al);
}
}
</script>
<form name="form2" action="browseservlet" >
<select name="category" onchange="sub2()">
<option value="">category</option>
<% for(int i = 0; i<category.length; i++)
{ %>
<option value="<%= urlct %>" ><%= category %>, <%= countct %> nos</option>
<% } %>
</select>
</form>

regards
 
mbrooks thanks for your idea. But did not work. I get the same error. What does the error mean.

Thanks

 
I changed my form name to different names, but still no sucess. Any suggestions. Thanks in Advance.

Regards
 
This seems to work. It's likely something else is wrong within your script.
Code:
<script type="text/javascript">
<!--//
function submitForm() {
	document.this_form.submit();
}
//-->
</script>

<form name="this_form" action="[URL unfurl="true"]http://google.com">[/URL]
<select name="field" onChange="submitForm()">
<option value="">Select</option>
<option value="test">Test Me</option>
</select>
</form>

M. Brooks
 
No the same piece of code is workign fine with other program. But the same is not working in this program. I am wondering why this erro comes.

THanks
 
is it possible that the code is being executed before the page is fully loaded? Trying throwing some alerts in there to see what's happening when.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Try viewing the page in Firefox. Then click on Tools, and Javascript Console. This most likely will give you the error and the line it's on.

Lee
 
Load the page then do a View/Source and copy that output to show here so we can see the whole code as it is rendered by the browser.

It is entirely possible that there is an error elsewhere on the page like an extra or missing bracket that screws up the javascript functions.

Also, you are mixing server-side and client-side script.
You should have a declaration on the page stating the script types rather than just a <script> tag.

You do not show it but I assume you have a complete HTML page with HTML, HEAD and BODY tags?. If you do not have these then a call to document.formname might fail since document would be refering to the HTML page object and I do not know how the script would operate if it HTML has not been properly declared.


It's hard to think outside the box when I'm trapped in a cubicle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top