Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limiting Type of Files to Upload

R5 - Web Applications

Limiting Type of Files to Upload

by  NiteLink  Posted    (Edited  )
Place the following in the JS Header:

Code:
function LimitAttach(form, file) {
allowSubmit = false;
extArray = new Array(".gif", ".jpeg", ".jpg");
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("Please only upload files that end in types: " + (extArray.join(" ")) + "\nPlease select a new file to upload and submit again.");
}

In the HTML Attributes of the File Upload Control, put uploadfile in the ID.

Place the following in the onClick of the button:

Code:
LimitAttach(this.form, this.form.uploadfile.value)
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top