Solved

Null or not an Object error

Posted on 2007-03-20
7
1,131 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 29

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 29

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 29

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 29

Expert Comment

by:Pravin Asar
ID: 18759407
You are welcome.

Glad to be of some help..

_PA
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

627 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