caclark
06-03-2005, 01:52 PM
I have a simple file extension function (shown below) but I need to use an "onblur" call of my function from a form file input (use this approch because form field is not always visible on the page, so I can't use "onsubmit" because the field will not always be used).
Now back to my question. IE seems to "lose focus" when the file chooser is displayed. And hence my function executes and as designed in the function an Error message is displayed. I have no problems in any other browsers (Mozilla, FireFox) but my primary audience still uses IE.
Any help to aleviate this problem in IE would be appreciated.
JS Function:
function verifyFileType(fieldValue,delimiter,allowExtsArray,alertText,reloadPage){
if(fieldValue.split(delimiter).length<2){
alert("No File Extension Given!\n Please Retry The File Name Again.");
return false;
}
var parts=fieldValue.split(delimiter);
var lowerCaseParts=parts[1].toLowerCase();
var validExt="no";
for (i=0;i<allowExtsArray.length;i++){
if(lowerCaseParts==allowExtsArray[i]){
validExt="yes";
return;
}
}
if(validExt=="yes"){
return true;
}
else {
alert(alertText);
if(reloadPage==1){
window.location.reload();
}
return false;
}
}
Page Input:
<form name="fileUploadForm" enctype="multipart/form-data" method="post">
<span class="s-txt"><b>Enter Filename</b></span>
<input type="file" name="fileName" size="40"
onblur="return verifyFileType(this.form.fileName.value,'.',['txt','log'],'Invalid File Type. \n\n Must Be A Text File. With A \(.txt or .log\) Ending.',0)">
<p><input type="submit" value="Upload File">
<input type="reset" value="Clear Form">
</form>
Now back to my question. IE seems to "lose focus" when the file chooser is displayed. And hence my function executes and as designed in the function an Error message is displayed. I have no problems in any other browsers (Mozilla, FireFox) but my primary audience still uses IE.
Any help to aleviate this problem in IE would be appreciated.
JS Function:
function verifyFileType(fieldValue,delimiter,allowExtsArray,alertText,reloadPage){
if(fieldValue.split(delimiter).length<2){
alert("No File Extension Given!\n Please Retry The File Name Again.");
return false;
}
var parts=fieldValue.split(delimiter);
var lowerCaseParts=parts[1].toLowerCase();
var validExt="no";
for (i=0;i<allowExtsArray.length;i++){
if(lowerCaseParts==allowExtsArray[i]){
validExt="yes";
return;
}
}
if(validExt=="yes"){
return true;
}
else {
alert(alertText);
if(reloadPage==1){
window.location.reload();
}
return false;
}
}
Page Input:
<form name="fileUploadForm" enctype="multipart/form-data" method="post">
<span class="s-txt"><b>Enter Filename</b></span>
<input type="file" name="fileName" size="40"
onblur="return verifyFileType(this.form.fileName.value,'.',['txt','log'],'Invalid File Type. \n\n Must Be A Text File. With A \(.txt or .log\) Ending.',0)">
<p><input type="submit" value="Upload File">
<input type="reset" value="Clear Form">
</form>