Solved

Null or not an Object error

Posted on 2007-03-20
7
1,121 Views
Last Modified: 2012-06-27
Hi Experts,

   I  have the following script

function doCheck() {
      //if(checkAndSubmit()){
      if(!(document.attachmentForm.attachmentType.item(0).checked ||
             document.attachmentForm.attachmentType.item(1).checked)){
             alert("Please select Option");
             return false;
       }      

             
       var fileName=document.attachmentForm.fileAttached.value;
      if(document.attachmentForm.attachmentType.item(0).checked)
            return true;
                  
       if(fileName==null || fileName=="")
             return true;
       var compressFormat1 = document.attachmentForm.compressFormat.value;
       var fileFormat1 = document.attachmentForm.fileFormat.value;
       var ss = fileName.split(".");       

       var extention = ss[ss.length-1];
       //alert("Form: "+extention +";"+compressFormat1+";"+fileFormat1);       
       if(checkRestictedFiles(extention)){
             alert("You can't upload executable and system files (exe, dll, bat,cmd) files");
             return false;       
       }
      
       if(checkFileFormat(extention,fileFormat1,compressFormat1))
             return checkAndSubmit();
       else{
             alert("File extention is not associated with the specified file format. Please make sure that you have specified the correct file");
             return false;
       }
      
       return checkAndSubmit();
       /*
      }else{
       return false;
      }      
      */

}

I am calling that script while submitting the form like this

<html:form  onsubmit="return doCheck();" method="post" action="/firegrant/jsp/share/saveAttachments" enctype="multipart/form-data" >

But when I am submitting the form, Iam getting the following error
 document.attachmentForm.attachmentType is null or not an Object.

Please tell me the reason why I am getting that error.

I have two questions
1) We have not given any name for the form , but in the script he is using as attachmentForm.  But when I debug the script error , I am seeing the name of the form as AttachmentForms  as below

<form name="AttachmentsForm" method="post" action="/firegrant/jsp/share/saveAttachments.do" enctype="multipart/form-data" onsubmit="return doCheck();">
Why is it so?

2)  what is checkAndSubmit()

Thanks
TirupatiReddy
0
Comment
Question by:manyam537
  • 4
  • 3
7 Comments
 
LVL 28

Accepted Solution

by:
Pravin Asar earned 500 total points
Comment Utility
change
 AttachmentsForm

to

attachmentForm



To help you debug such situation, you can add the code to you page..


<html>
<head>
<title>Catch error </title>
</head>

<body>
<script language="javascript">
function handleErr(err)
{
txt="There was an error on this page.\n\n"
txt+="Error: " + err + "\n"
alert(txt)
return true
}
onerror=handleErr
//alert ('Message  ' + myvar);
</script>
<body>
</html>
0
 

Author Comment

by:manyam537
Comment Utility
HI pravinasar,

  I don't have form name in my page. So where do I change? While debugging I am geeting the form name and in my page I have not given the form name.

Thanks
TirupatiReddy
0
 
LVL 28

Expert Comment

by:Pravin Asar
Comment Utility
function doCheck() {
      //if(checkAndSubmit()){
      if(!(document.attachmentForm.attachmentType.item(0).checked ||
             document.attachmentForm.attachmentType.item(1).checked)){
             alert("Please select Option");
             return false;
       }      

             
       var fileName=document.attachmentForm.fileAttached.value;
      if(document.attachmentForm.attachmentType.item(0).checked)
            return true;
                   
       if(fileName==null || fileName=="")
             return true;
       var compressFormat1 = document.attachmentForm.compressFormat.value;
       var fileFormat1 = document.attachmentForm.fileFormat.value;
       var ss = fileName.split(".");      

       var extention = ss[ss.length-1];
       //alert("Form: "+extention +";"+compressFormat1+";"+fileFormat1);      
       if(checkRestictedFiles(extention)){
             alert("You can't upload executable and system files (exe, dll, bat,cmd) files");
             return false;      
       }
       
       if(checkFileFormat(extention,fileFormat1,compressFormat1))
             return checkAndSubmit();
       else{
             alert("File extention is not associated with the specified file format. Please make sure that you have specified the correct file");
             return false;
       }
       
       return checkAndSubmit();
       /*
      }else{
       return false;
      }      
      */

}
<form name="attachmentsForm" method="post" action="/firegrant/jsp/share/saveAttachments.do" enctype="multipart/form-data" onsubmit="return doCheck();">
<input type="file" name="fileAttached">
...
... Add your other fields
....

<input type="submit">
</form>

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:manyam537
Comment Utility
Hi ,

  I don't have the name attribute in html:form . I am not using html tags here. I am using struts html tag library, in which I don't have the name attribute.

Thanks
TirupatiReddy
0
 
LVL 28

Expert Comment

by:Pravin Asar
Comment Utility
do you assign id to html elements?
0
 

Author Comment

by:manyam537
Comment Utility
Hi pravinasar,

    I resolved it. It is taking the form Name from  action which is using the form bean with name AttachmnetsForm . So now I changed my script and replaced the attachmentForm with AttachmentsForm.

  Anyway  your solution helped me a little bit in thinking the right direction.

Thanks
TirupatiReddy
0
 
LVL 28

Expert Comment

by:Pravin Asar
Comment Utility
You are welcome.

Glad to be of some help..

_PA
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now