Null or not an Object error

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
manyam537Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pravin AsarPrincipal Systems EngineerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
manyam537Author Commented:
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
Pravin AsarPrincipal Systems EngineerCommented:
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

manyam537Author Commented:
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
Pravin AsarPrincipal Systems EngineerCommented:
do you assign id to html elements?
0
manyam537Author Commented:
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
Pravin AsarPrincipal Systems EngineerCommented:
You are welcome.

Glad to be of some help..

_PA
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.