I have 2 Javascript functions that I want to perform when a form is submitted. The first is a check to see if a valid extension exists on a file input field. If that comes back good, I want the second to be excecuted. I would like to keep the 2nd function as the main OnSubmit field in the FORM. Here are the functions
Function 1 (check extension of field.)
<script language="JavaScript">
//Function to check for valid file extension
extArray = new Array(".jpg", ".png", ".bmp", ".gif", ".wmv");
function LimitAttach(form, file) {
allowSubmit = false;
if (!file) return;
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\
\") + 1);
ext = file.slice(file.indexOf(".
")).toLowe
rCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) { allowSubmit = true; break; }
}
if (allowSubmit) return true;
else
alert("Please only upload files that end in types: "
+ (extArray.join(" ")) + "\nPlease select a new "
+ "file to upload and submit again.");
return false;
}
// End -->
</script>
And if that one comes back ok, I want it to procede with Function 2:
function ProgressBar(form){
//ASP script handling progress window
var ProgressScript
ProgressScript = 'progress-smooth.asp'
//Progress window parameters
var pp = 'toolbar=no,location=no,di
rectories=
no,status=
no,menubar
=no'
pp+=',scrollbars=no,resiza
ble=no,wid
th=353,hei
ght=200';
//1. Get unique UploadID
var UploadID
UploadID = Math.round(Math.random() * 0x7FFFFFF0)
//2. Add upload ID to form action URL
var action = form.action;
if ('' == action) action = ''+document.location;
action = AddToQuery(action, 'UploadID', UploadID);
form.action = action
//alert(form.action)
//3. Open progress window with the same UploadID
var ProgressURL
ProgressURL = ProgressScript + '?UploadID=' + UploadID
var v = window.open(ProgressURL,'_
blank',pp)
return true;
};
I want my <FORM> tag to look like this:
<form name="file_upload" method="POST" ENCTYPE="multipart/form-da
ta" OnSubmit="return ProgressBar(this);">
So basically just roll the IF/THEN function 1 into function 2. Pretty simple, huh!