This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 1398
    
    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: 1398
    
    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: 1398
    
    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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javascript function returns document.forms.0 null or not an object error
 
Similar Threads
Java Script problem
Script error
Pl Help me this error
error on tag
How to disable all form elements