/    Sign up×
Community /Pin to ProfileBookmark

File upload filter

I am using the file upload filter located here on a form that may or may not have a file attachment:
[url]http://javascript.internet.com/forms/upload-filter.html[/url]

It works fine except, if there is not a file to be uploaded. Nothing happens. I can write some simple scripts but can not figure out how to modify the code to just submit the form if there is no upload file. Any help would be appreciated. ?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@JonaJun 03.2005 — [font=Trebuchet MS]Give this a shot.[/font]

<i>
</i>&lt;script type="text/javascript"&gt;&lt;!--
extArray = new Array(".gif", ".jpg", ".png");
function LimitAttach(form, file) {
allowSubmit = false;
if (!file) {
form.submit();
return;
}
while (file.indexOf("\") != -1)
file = file.slice(file.indexOf("\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i &lt; extArray.length; i++) {
if (extArray[i] == ext) { allowSubmit = true; break; }
}
if (allowSubmit) form.submit();
else
alert("Please only upload files that end in types: "
+ (extArray.join(" ")) + "nPlease select a new "
+ "file to upload and submit again.");
}
//--&gt;&lt;/script&gt;
Copy linkTweet thisAlerts:
@pbaldwinauthorJun 03.2005 — Thank you very much. I tried: ?

if (!file) {

form.submit();

}

Thinking this would work but it didn't obviously. I am now going to read again and again and..
Copy linkTweet thisAlerts:
@JonaJun 03.2005 — [font=Trebuchet MS]The only difference is the [i]return[/i] statement, which ends the function right there (and prevents any further processing in the function).

Happy to help.[/font]
Copy linkTweet thisAlerts:
@VastconceptJul 13.2005 — Hi There,

I am a beginner in need of help. Is there a way to loop so that files with multiple "." in it can be accepted? example: .jpg is an accepted extension, but if the file is named "image1.2.jpg", the script thinks its the incorrect extension.

Also, is there a way to make this work for Unix clients?

Thanks in advance!
×

Success!

Help @pbaldwin 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.18,
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,
)...