Solved

How to Download a File with either jQuery or Javascript

Posted on 2012-03-23
3
298 Views
Last Modified: 2012-03-23
So I have already asked this question once and the previous expert refused to answer since I didn't ask it explicitly.

What I am trying to do with this code is actually allow a user to choose a value from a drop down box. Once they do that, it will trigger an onchange event, to download the file. You get the little dialog box for run or save and the like.

That is what I want. What I cobbled together, and the expert helped me correct, is redirecting to a new window.

How do I, using the base code I have, get a file to download?

I would just use links, but my boss wants a drop down.

Thanks for any help, which I'm not sure, I'll get. :-/

<html>
<head>
<script script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script>
$(function() {
     $("#PrinterNames").change(function() {
         var printer = $(this).val();
        var url = "C:\Users\JBenson\Desktop\Printer Scripts\Completed" + printer +".vbs";
	console.log(url);
        window.open(url,'Start Installation')
     });
});
</script>      

</head>

<body lang=EN-US style='tab-interval:.5in'>

<img src=inspirelogo.gif>

<H2>Welcome to the HK Printer Installation Page!</H2>
      <H3>Please select a printer:
            <select id ="PrinterNames"  name ="PrinterNames" >
		  <option value="Please Select a Printer" selected="selected">Please Select a Printer</option>
		  <option value="Acadia">Acadia</option>
                  <option value="Altima">Altima</option>
                  <option value="Armada">Armada</option>
                  <option value="Avalon">Avalon</option>
                  <option value="Blazer">Blazer</option>
                  <option value="Camaro">Camaro</option>
                  <option value="Caravan">Caravan</option>
                  <option value="Cavalier">Cavalier</option>
                  <option value="Celica">Celica</option>
                  <option value="Charger">Charger</option>
                  <option value="Chevelle">Chevelle</option>
                  <option value="Corolla">Corolla</option>
                  <option value="Corvair">Corvair</option>
                  <option value="Corvette">Corvette</option>
                  <option value="Daytona">Daytona</option>
                  <option value="Envoy">Envoy</option>
                  <option value="Escalade">Escalade</option>
                  <option value="Frontier">Frontier</option>
                  <option value="HHR">HHR</option>
                  <option value="Hummer">Hummer</option>      
                  <option value"Impala">Impala</option>
                  <option value="Insight">Insight</option>
                  <option value="Intrepid">Intrepid</option>
                  <option value="Journey">Journey</option>
                  <option value="Malibu">Malibu</option>
                  <option value="Maxima">Maxima</option>
                  <option value="Murano">Murano</option>
                  <option value="Neon">Neon</option>
                  <option value="Nomad">Nomad</option>
                  <option value="Nova">Nova</option>
                  <option value="Prowler">Prowler</option>
                  <option value="Sentra">Sentra</option>
                  <option value="Skyline">Skyline</option>
                  <option value="SSR">SSR</option>
                  <option value="Stratus">Stratus</option>
                  <option value="Versa">Versa</option>
                  <option value="Xterra">Xterra</option>
            
            </select> </H3>

<H3>Steps for Printer Installation </H3>
<ol>
      <li>Select your printer from the drop down above.</li>
      <li>You will get a pop up window that looks like this<br>
      <img src="printerinstall.jpg" alt="Download Box" ><br>
      Please click on open. It will iniate the installation.<br></li>
      <li>You may see a pop up box that looks like this during your installation<br>
      <img src="trustprinter.jpg" alt="Trust Printer"><br>
      Click on Install driver. <br></li>
      <li>After a few minutes, check your Devices and Printers and the printer you selected should now be there.</li>
</ol>
<H3>Please contact the helpdesk at 6657 if you encounter any issues. </H3>

</body>
</html>

Open in new window

0
Comment
Question by:JamiBenson092279
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
Lalit Chandra earned 500 total points
ID: 37759076
This is not the way to address links for local files --

 they must be preceded by file:///, in the same way you'd start a normal web URL that requires the http protocol with http://. A URL in the format C:/whatever is interpreted as needing a protocol named C. The error message tells you that no program has been associated with a protocol named C.

OR

Or use backslashes ('c:\') then Firefox will change it to the 'file:///' format (at least that works for me).
0
 

Author Closing Comment

by:JamiBenson092279
ID: 37759106
That was all I needed. I appreciate you coming back and finishing the answer. That was all I needed. It works absolutely perfect now.

Thank you so very much for all your help. I can finally put this to bed!!!

Again I can't say thank enough for giving me exactly what I needed!
0
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37759120
Oh god !!!
   You can't imagine how i m feeling now when you told that now you got wht you needed.
Once again don't take my previous words to your heart, it's just happd.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 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

22 Experts available now in Live!

Get 1:1 Help Now