Solved

Browse for File, capture filename, do not upload file

Posted on 2007-11-16
2
706 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

929 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

10 Experts available now in Live!

Get 1:1 Help Now