Browse for File, capture filename, do not upload file

I need a file browse feature added to my web site.  Similar to the <input type="file"> feature, but it will only capture the name of the file and insert it into a text field on the form.  It SHOULD NOT attempt to upload the file to the web server when the form is submitted.
Who is Participating?
den4bConnect With a Mentor Commented:
You can use javascript on your submit button to extract the filename and remove the FILE element from the page. The sample code is shown below:
    function extract_file_name()
      var file = document.getElementById('file');
	  if (!file) return false;
      var filename = file.value; 
      var pos = filename.lastIndexOf('\\');
      if (pos >= 0) filename = filename.substring(pos+1, filename.length);
      return filename;
  <input id="file" type="file"><br><br>
  <button onclick="alert(extract_file_name())">Extract File Name</button>

Open in new window

benlaneAuthor Commented:
Thanks a lot!  Worked Great!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.