PaulHanak
PaulHanak

Reputation: 739

using jquery in a REGULAR javascript ...script?

I am not really sure how to word the question, but I basically have an old javascript that checks file extensions of a user upload BEFORE it is sent to the server for processing. (Just for the admin section of a website.)

Well, I want a div to slideDown() whenever a javascript condition returns true inside a loop (meaning, the file is good to upload).

Code so far:

  var thisext = fieldvalue.substr(fieldvalue.lastIndexOf('.'));
for(var i = 0; i < extension.length; i++) {
    if(thisext == extension[i]) { return true;

            $("#pleasewait").slideDown();

         }
    }
alert("Please upload ONLY .mp3 files. No other files will work.");
return false;
}

Upvotes: 1

Views: 89

Answers (2)

Mario J Vargas
Mario J Vargas

Reputation: 1195

The code has a textbook case of a logical error. The slidedown should occur before the return statement because the function will exit immediately after that line.

Try this within your function:

var thisext = fieldvalue.substr(fieldvalue.lastIndexOf('.'));
for(var i = 0; i < extension.length; i++) {
    if(thisext == extension[i]) { 
        $("#pleasewait").slideDown();

        return true;
     }
}

alert("Please upload ONLY .mp3 files. No other files will work.");
return false;

Upvotes: 3

xdazz
xdazz

Reputation: 160983

You should put return true; after $("#pleasewait").slideDown();

Upvotes: 5

Related Questions