Solved

Browse for File, capture filename, do not upload file

Posted on 2007-11-16
2
705 Views
Last Modified: 2010-04-21
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.
0
Comment
Question by:benlane
2 Comments
 
LVL 6

Accepted Solution

by:
den4b earned 500 total points
ID: 20298831
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:
<html>

<head>

  <script>

    function extract_file_name()

    {

      var file = document.getElementById('file');

	  if (!file) return false;

      var filename = file.value; 

      file.parentNode.removeChild(file);

      var pos = filename.lastIndexOf('\\');

      if (pos >= 0) filename = filename.substring(pos+1, filename.length);

      return filename;

    }

  </script>

</head>

<body>

  <input id="file" type="file"><br><br>

  <button onclick="alert(extract_file_name())">Extract File Name</button>

</body>

</html>

Open in new window

0
 

Author Closing Comment

by:benlane
ID: 31409562
Thanks a lot!  Worked Great!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now