Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javascript function returns document.forms.0 null or not an object error

 
Deepa Kulkarni
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using jsp and java script function and calling java script function on onclick property of <a></a> tag but while clicking on link I am getting document.forms.0 null or not an object error.
Please suggest.
 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepa,

Without looking at your code, its tough to know what's going wrong.
 
Deepa Kulkarni
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Swastik,

I have a main.jsp in which I have included another jsp ,(another.jsp).

Please find the code below.

main.jsp :-

<body>
<div>
<form method="post">
<jsp:include page="/WEB-INF/search/another.jsp"></jsp:include>
</form>
</body>
----------------------------------------------------------------------------

another.jsp :-

<table>
<tr>
<td>
<div>
<a href="#" onclick="submitFunction();">Go</a>
<div>
</td>
</tr>
</table>
----------------------------------------------------------------------------

index.js :-

function submitFunction()
{
document.forms[0].action = "http://www.google.co.in";
document.forms[0].submit();
}

Above submit function throws an error message document.forms.0 is null or not an object.
 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In which page are you using . I tested your code, works fine.
 
Deepa Kulkarni
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inside main.jsp the script is added.
 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then it has to work. Try it once again.

main.jsp
-----------




and a I guess the .js file is in the same folder where main.jsp exist, or else you have to specify the path of js file, and one more thing, next time if you show your code here, please use code tags.
 
Deepa Kulkarni
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sure.Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic