Announcement

Collapse
No announcement yet.

How to create a download button?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to create a download button?

    This seems like it should be so very easy. I have never had the need to use a download button before. I am now trying to set one up, but it always tries to open the file instead. Any one have a short and simple code that could be used in the 'onclick' of a button to download a file, without trying to open it?

    This opens a file very nicely, now if only it could be rewritten to perform a download...

    To retrieve a file, after we have notified you it is ready for retrieval, enter in the box below the same name you entered to upload the
    file. (Such as 'companyname.qbb') Then click the 'Download' button and select 'Save'.
    <form name=form1>
    <input type=text name="datafile" size="50"><br>
    <input type=button onClick="location.href='/files/' + document.form1.datafile.value;" value="Download">
    </form>


    If the file format (file extension) is not recognized by your operating system, it works as I wish. If the file is one that is recognized, .txt, .doc etc. it opens.



  • #2
    Hopefully this will help you out.

    onClick="saveFile('this.doc');"

    Or what I did was do a google search for "onclick save target as"

    Comment


    • #3
      Thanks for your reply.

      I was doing a search for 'download file' and 'file download'. Needless to say, I was getting tons of junk in those searches.

      I tried your method, it requires a javascript companion file. I went to that site and copied that code, but it does not really work. I also read many of the other links returned in your suggested google search, and most of them say that what I want to do cannot be done. Which is odd, since I have been to many pages, including Microsoft pages, that have a button to start the download. It is even OK if it opens a window with options to run or view or whatever, if it would just not automatically try to open the file in it's proper program.

      Thanks again, you got me a bit farther along, I will keep searching.

      Comment


      • #4
        LOL!

        I just did some more tweeking on that code you pointed me to, and IT NOW WORKS!

        Chuckle, Thanks a bunch.

        Here is what I wound up with:

        In the head of the html page:
        <SCRIPT LANGUAGE="JavaScript">
        <!-- Begin
        function saveFile ()
        {
        document.execCommand('SaveAs',null,'files/' + document.form1.report.value)
        }
        // End -->
        </script>

        And in the body:
        <form name=form1>
        <input type=text name="report" size="50"><br>
        <input type=button onClick="saveFile();" value="Download">
        </form>

        Comment

        Working...
        X