Solved

Browse for File, capture filename, do not upload file

Posted on 2007-11-16
2
710 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

732 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