/    Sign up×
Community /Pin to ProfileBookmark

check extenstions on multiple file attachments

Hi,

Can someone tell me what I am doing wrong. Script works on the first attachment but not the other two?

[CODE]<script type=”text/javascript” language=”JavaScript”><!–
function ExtensionsOkay() {
var extension = new Array();
var fieldvalue = new Array();
fieldvalue[0] = document.customApp.attachment_1.value;
fieldvalue[1] = document.customApp.attachment_2.value;
fieldvalue[2] = document.customApp.attachment_3.value;
extension[0] = “.doc”;
extension[1] = “.docx”;
extension[2] = “.txt”;
extension[3] = “.pdf”;

// No other customization needed.
for(var f = 0; f < fieldvalue.length; f++) {
var thisext = fieldvalue[f].substr(fieldvalue[f].lastIndexOf(‘.’));
for(var i = 0; i < extension.length; i++) {
if(thisext == extension[i]) { return true; }
}
alert(“Your upload field ” + f + ” contains an unapproved file name.”);
return false;
}
}
//–></script>[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@TiGGiauthorSep 10.2009 — Anyone? please!!!
Copy linkTweet thisAlerts:
@justinbarneskinSep 11.2009 — the return is exiting the function before it gets done.

I think it needs two loops or two functions,

I'll be back in a few minutes....
Copy linkTweet thisAlerts:
@justinbarneskinSep 11.2009 — [code=html]
for(var f = 0; f < fieldvalue.length; f++) {
var thisext = fieldvalue[f].substring(fieldvalue[f].lastIndexOf('.'),fieldvalue[f].length);
for(var i = 0; i < extension.length; i++) { var ok=0
if(thisext == extension[i]) { ok=1 ; i= extension.length }
}
if( ok==0){ alert("Your upload field " + f + " contains an unapproved file name."); }
}
}
[/code]
×

Success!

Help @TiGGi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...