我通过表单获取文件,并要求验证其类型。但听起来java脚本不起作用或没有看到调用?
<form enctype="multipart/form-data" action="Upload2.jsp"
method="post" onsubmit="javascript:return validate();">
<td><b>Choose txt file To Upload:</b></td>
<td><input name="file" type="file"></td>
<td><input type="submit" value="Upload File" ></td>
</form>
这是脚本:
<script language="JavaScript">
function validate(){
if(document.form.file.value == "" ) {
alert("Enter course code !");
return false;}
else {
var value = document.form.file.value;
var ext = value.substr(dot, value.length);
//ext = value.slice(file.indexOf(".")).toLowerCase();
if ( ext=="txt" ) {
return true; }
else{
alert("choose a .txt file");
return false;}
}
}
</script>
这是表格..我不确定我的脚本是否正确?