Solved

How to Download a File with either jQuery or Javascript

Posted on 2012-03-23
3
304 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
[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
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

696 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