views:

72

answers:

4

i have a javascript function

 function alertMe(len)
 {
     var fu1 = document.getElementById("FileUpload1");
     var fu2 = document.getElementById("FileUpload2");
     var fu3 = document.getElementById("FileUpload3");
     var fu4 = document.getElementById("FileUpload4");
     var myCars=new Array(fu1,fu2,fu3,fu4)
     var l=0;
     for(var i=0;i<myCars.length;i++)
     {
         if(myCars[i].value!=null)
             l++;
     }
     if(len>6)
     {
         if(len==7 && l<=3)
           window.location="uploo.aspx";
         else if(len==8 && l<=2)
           window.location="uploo.aspx";
         else if(len==9 && l<=1)
           window.location="uploo.aspx";
         else
           alert("you cant keep more than 10 files in your table,,delete some files first and then upload");
         return false;
     }
     else
         window.location="uploo.aspx";
 }

this function gets a value len and based on that checks some conditions,,in addition to that i m trying to retrieve the IDs of four file upload controls,,the purpose is to get the number of files browsed,,the function does not give any errors but is not working properly.. suppose if len=7 and l=3,then it should call uploo.aspx but rather it shows me the alert messages..i want to know, is their any error in retrieving the value of l..

A: 

It seems like you are doing a bunch of extra work for tools that are already out there. Try out uploadify. I believe you can set a limit for the number of files that can be uploaded, as well as limit the types of files that can be uploaded. They can also upload multiple files at once.

jmein
actually the no of files user uploads are stored in a gridview,,and i m trying to limit my number of rows in grdiview and not on uploaded files
sumit
A: 

For sanity's sake, I'd start by adding the missing semicolon to the end of your var myCars line. In some IE browsers, they'll choke in weird ways if you're missing those semicolons.

If all four of the vars fu1-4 have values, then your variable l is going to be 4, which you don't explicitly check for, and which will fall through to the alert() error case (assuming len > 6).

I'd liberally add some more debugging tracer output -- add an alert('l=' + l ', and len=' + len) after your for loop, for example.

bantic
A: 

try using if(myCars[i].value) instead of checking against null - value is a string and even an empty string is unequal null.

Joscha
A: 

You can check the values using firebug:

console.log(l);

If you put this within the switch you should be albe to see the values that are being used in the firebug console.

matpol