Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enctype Error

Stephen Wei
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all:
I am uploading a file to my servlet. Before doing so, on the client side I use Javascript to check if the file is csv or not. The checking is ok, but then my servlet says Enctype error.
Notice that if I remove the Javacript checking, the file is uploading fine. So what is wrong with my approach? how to fix it?
Following is my code, thanks.
<script language = "javascript">
function fileFormSubmit()
var error1 = "please select csv file";
var error2 = "please select GIF file";
window.event.returnValue = false;
var string = uploadForm.fileName.value.substr((uploadForm.fileName.value.lastIndexOf(".")+1));

if ((string != "csv")&&(string != "CSV"))
window.event.returnValue = true;


<form ID="uploadForm" action="../servlet/Upload" METHOD=POST ENCTYPE="multipart/form-data" onsubmit = "fileFormSubmit()">
<p align="center"> <INPUT TYPE=FILE NAME=file1> </p>
<p align="center"> <INPUT TYPE=SUBMIT> </p>
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic