How to Download a File with either jQuery or Javascript

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

JamiBenson092279Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Lalit ChandraConnect With a Mentor Commented:
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
 
JamiBenson092279Author Commented:
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
 
Lalit ChandraCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.