Reputation: 739
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
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