上传文件的Form 里,浏览文件夹的Input Field 的属性和一般的input是不一样的,所以不能用getElementById取值。必须用:
document.formName.id.value 来取值。
可以用它判断上传文件的类型,限制用户上传文件类型。
例子:
上传form:

Code
<form id="Preview_Form" name="Preview_Form" method="post" enctype="multipart/form-data" action="upload.asp?itemid=<%=itemID%>&catid=<%=catID%>" onsubmit="return ValidateImgFormat(this)">
<table width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td>Front Side Image (3MB is MAX Image Size,JPEG Format Only)</td>
</tr>
<tr>
<td>Upload :
<label>
<input type="file" name="FrontImage" id="FrontImage" />
<input type="submit" name="uploadImage" id="uploadImage" value="Upload" />
</label></td>
</tr>
</table>
</form>
Javascript code:

Code
<script language="javascript">
function ValidateImgFormat(theform){
var str=document.Preview_Form.FrontImage.value;
var ext= str.substring(str.length-3);
ext =ext.toLowerCase();
if (ext!="jpg" || ext!="jpeg") {
alert("Please upload a vaild format image.");
return false;
}
return true;
}
</script>
这样,如果用户不是上传的jpeg图片,就会提示错误,停止上传。