1

I have the following code:

function check Files()
{
    if (jQuery.isEmptyObject($('#fileupload').files) == true){
        changeStage1Class();
    }
}

The code is checking if something is uploaded. When it's empty it returns "true". But even when there is a file uploaded it still returns "true". Is the code not working correctly?

2
  • try === instead of == . Commented May 23, 2015 at 23:55
  • The problem is back again. ? Commented May 23, 2015 at 23:59

1 Answer 1

1

$('#fileupload') gives you jQuery object and not the direct html element, you need to invoke get() on it:

$('#fileupload').get(0).files

Also you cannot have spaces between names:

function check Files() {
             ^^
}

$('#fileupload').get(0).files.length gives the file count > 0, if file was chosen

Try this:

if ($('#fileupload').get(0).files.length){
   changeStage1Class();
}
Sign up to request clarification or add additional context in comments.

5 Comments

Yeah, sorry that was a mistake of copying the code here by my part. I did what you said and it works now. Thanks a lot!
I just changed the (0) to (1) and it works now. Is that a sufficient change?
I've got fileupload.js fileupload-process.js etc etc
Thats strange, do you have multiple <input type='file' id='fileupload'/> with same id fileupload ?
No I don't. All I want the code to do is return to "stage1" if there are no files left. What it is doing now is if I upload multiple files and delete 1 they all disappear and I go back to "stage1". With your code ".get(1)" I can delete 1 file at a time without going back to "stage1" but even when I delete all of the files and there is nothing left, I am not redirected to "stage1".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.