Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 27th, 2003, 10:05 PM
Registered User
 
Join Date: Jun 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default download button - dynamic change filename

Hi everyone,

Can you help with code sample please.

I like to have a dropdown box list all all my files. Next to the box is a botton 'go/download'. The button will download the file the user selects from the dropdown box.

Thankyou

Tom N
 
Old November 28th, 2003, 04:36 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Assumuing you have a dropdown with the id of "lstFiles" with the friendly name showing and the path to the file in the option value you need the button onclick call a function like:
Code:
<input type="button" value="Download File" onclick="downloadFile();">

function downloadFile()
{
  var oLst = documentGetElementById("lstFiles");
  var iIndex = oLst.selectedIndex
  if (iIndex  > -1)
  {
    var sPath = oLst.options[iIndex].value;
    window.open(sPath, "");
  }
  else
  {
    alert("Please select a file.");
  }
}
If the file is a known type that the browser knows how to display it will come up displayed either in the browser or in the relevant application depending on how the client is configuered. If it is an unknown type the uswer will get the download or save dialog box. If you wish to always have the dialog box, even for files such as .txt. Then you will need to set the response headers using a server-side technology such as ASP. Look on msdn.com at:
http://support.microsoft.com:80/supp...NoWebContent=1



--

Joe





Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamic change of style rajesh_css Javascript 3 October 10th, 2008 04:45 AM
Change onclick of a button me_zeta HTML Code Clinic 1 November 20th, 2006 10:34 AM
Changing the filename for download Byock C# 0 August 1st, 2006 10:23 PM
Dynamic Filename ozPATT Access VBA 1 November 28th, 2005 01:56 PM
Dynamic Backcolor change in VB caltito Access VBA 0 August 22nd, 2004 09:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.