File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Javascript function returns document.forms.0 null or not an object error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Javascript function returns document.forms.0 null or not an object error" Watch "Javascript function returns document.forms.0 null or not an object error" New topic
Author

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

Deepa Kulkarni
Greenhorn

Joined: Feb 20, 2012
Posts: 6
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

Joined: Jan 08, 2009
Posts: 1454
    
    6

Deepa,

Without looking at your code, its tough to know what's going wrong.


Swastik
Deepa Kulkarni
Greenhorn

Joined: Feb 20, 2012
Posts: 6
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

Joined: Jan 08, 2009
Posts: 1454
    
    6

In which page are you using . I tested your code, works fine.
Deepa Kulkarni
Greenhorn

Joined: Feb 20, 2012
Posts: 6
Inside main.jsp the script is added.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1454
    
    6

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

Joined: Feb 20, 2012
Posts: 6
sure.Thanks
 
Consider Paul's rocket mass heater.
 
subject: Javascript function returns document.forms.0 null or not an object error