?
Solved

Null or not an Object error

Posted on 2007-03-20
7
Medium Priority
?
1,132 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 1500 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

719 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