Online Shopping : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to
Did You Find This Entry Useful?

12 of 32 people (38%) answered Yes
Recently 4 of 10 people (40%) answered Yes


the accept attribute for the <input type=file> is not working in IE6.0 ..Is there any work around fo

Apr 8th, 2008 18:16
ha mo, Dave Clark, ll ll,

     The work-around is to check the file extension at the point where 
the user attempts to submit the form and cancelling such submission if 
this validation is unsuccessful.  However, note that the user may 
disable JavaScript execution to circumvent your validation attempts.  
Thus, the only sure-fire validation is performed by server-side code 
such as ASP, JSP, PHP, etc.  The following is the JavaScript-based 
var valid_extensions = /(.jpg|.jpeg|.gif)$/i;
function valid_extension(fld)
  if (valid_extensions.test(fld.value)) return true;
  alert('The selected file is of the wrong type.');;
  return false;
    Use the above JavaScript definitions with the following sample 
<form onsubmit="return valid_extension(this.elements['file_upload'])">
    <input type="file" name="file_upload" size="40">
Take care,
Dave Clark