
March 9th, 2005, 08:45 PM
|
 |
Alter Ego Wizard
|
|
Join Date: Jun 2004
Location: Edinburg Tx
|
|
Here is a full example of how it can be done:
Code:
<html>
<head>
<script language="JavaScript">
function checkFileExtension()
{
var temp = document.forms[0].elements["testfile"].value;
var fileExtension = temp.substring(temp.lastIndexOf('.') + 1,temp.length);
switch(fileExtension)
{
case "html":
return true;
break;
case "txt":
return true;
break;
default:
alert("File Extension " + fileExtension + " is invalid \nPlease Select Another File");
return false;
}
}
</script>
</head>
<body>
<form action="tst.asp" method="post" onSubmit="return checkFileExtension();">
<input type="file" name="testfile" />
<br />
<input type="submit" value="upload File">
</form>
</body>
</html>
All you have to do is keep adding to the switch statement valid file extensions.
It still needs some work for checking for blanks, but I'm sure you can handle that 
Feel free to post any questions you may have.
__________________
................... ASCII and ye shall receive ..................
Knowledge is the only resource on earth that multiplies when shared
Support the Shemzilla Project
Powered by C#
|