/    Sign up×
Community /Pin to ProfileBookmark

[Need help] How to disable the submit button if bad file extension?

I have searched but only found how to disable a button, not how to do it if its the wrong extension and I dont know much about JavaScript… I want to disable the submit button of a upload form if the file extension is not gif, jpg, jpeg, png or swf. Similar to [url]http://www.imageshack.us/[/url] but simpler.

The form looks like this:

[code=html]
<form action=”uploaded.php” method=”post” enctype=”multipart/form-data” name=”form1″>
<label for=”ufile”></label>
<div align=”left”>

<input name=”ufile” type=”file” class=”fileField” id=”ufile” size=”40″>
<input type=”submit” class=”Upload” value=”Upload!”>
</div>
<label for=””></label>
<div align=”left”></div>
</form>
[/code]

Thanks ?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@hoangkcSep 04.2007 — in the onchange event of [I][B]ufile[/B][/I], if its value contains wrong extension, you disable the submit button, else, you enable it.
Copy linkTweet thisAlerts:
@JikdorauthorSep 07.2007 — I got this script, havent realy made it myself, mostly copy and paste :rolleyes:

[CODE]<SCRIPT LANGUAGE="JavaScript">
extArray = new Array(".gif", ".jpg", ".png", ".jpeg", ".swf");
function LimitAttach(form, file) {
allowSubmit = false;
if (!file) return;
while (file.indexOf("\") != -1)
file = file.slice(file.indexOf("\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) { allowSubmit = true; break; }
}
if (allowSubmit) form.submit();
else
alert("That filetype is not allowed!ngif, jpeg, jpg, png and swf only.");
}
</script>[/CODE]


If a bad file type it will comea popup, but when when i click 'ok' it still sends the data... It shouldent do that of corse. If the file is ok i want the button tobe disabeld so it can't be clicked agian. the website is http://www.dreamuploader.com/ btw... Thanks if anyone is willing to help me out. ?
Copy linkTweet thisAlerts:
@felgallSep 08.2007 — You need to give the submit button a name or id so that you can reference it and then set the disabled attribute to true.
×

Success!

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