faqts : Computers : Programming : Languages : JavaScript : Forms : File Upload

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

47 of 78 people (60%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

Can I set the INPUT TYPE="file" element with drag and drop?

Apr 10th, 2000 14:28
Martin Honnen,


With NN4 and trusted script you can do so:

<HTML>
<HEAD>
<SCRIPT>
function dragDropHandler (evt) {
  netscape.security.PrivilegeManager.enablePrivilege
('UniversalBrowserRead');
  netscape.security.PrivilegeManager.enablePrivilege
('UniversalFileRead');
  var fileURL = evt.data[0];
  var fileName = 
    fileURL.substring(8).replace(/\|/g, ':').replace(/\//g, 
      java.lang.System.getProperty('file.separator'));
  document.formName.fileName.value = fileName
  return false;
}
window.ondragdrop = dragDropHandler;
</SCRIPT>
</HEAD>
<BODY>
Drag and drop a file in here.
<FORM NAME="formName"
      ACTION="yourFileUploadHandler"
      METHOD="post"
      ENCTYPE="multipart/form-data"
>
<INPUT TYPE="file" NAME="fileName">
<INPUT TYPE="submit">
</FORM>
</BODY>
</HTML>