Posted By

mohamedazher on 07/17/11


Tagged


Versions (?)

Getting File Name of File Upload


 / Published in: JavaScript
 

use this script to get the name of the file that you want to upload even before uploading it

  1. <script language="JavaScript"><!--
  2. function extract(what) {
  3. if (what.indexOf('/') > -1)
  4. answer = what.substring(what.lastIndexOf('/')+1,what.length);
  5. else
  6. answer = what.substring(what.lastIndexOf('\\')+1,what.length);
  7. alert(answer);
  8. }
  9. //--></script>
  10.  
  11. <form name="myform">
  12. <input type="file" name="myfile">
  13. <input type="button" value="Test" onClick="extract(this.form.myfile.value)">
  14. </form>

Report this snippet  

You need to login to post a comment.