Solved

Null or not an Object error

Posted on 2007-03-20
7
1,124 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
ID: 18758884
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
ID: 18758959
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
ID: 18758977
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:manyam537
ID: 18759083
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
ID: 18759145
do you assign id to html elements?
0
 

Author Comment

by:manyam537
ID: 18759325
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
ID: 18759407
You are welcome.

Glad to be of some help..

_PA
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

828 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