Download a File Using Javascript and Also use Drop Down Box ID in File Path

Howdy again experts :-)

I have a ::shudder:: Javascript question. I am writing a page for our intranet that will allow users to choose a printer out of a drop down box, hit a button and a script we have will open and install the printer.

Here is the code I have right now.

 
<html>
<head>
<script type="application/javascript">
function runPrinterInstall()
{ 
	
	var printer = getElementsbyName("PrinterNames")[0];
	var url = "C:\Users\JBenson\Desktop\Printer Scripts\Completed" + printer +".vbs"
	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 name ="PrinterNames" onchange ="runPrinterInstall">
			<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>Printer Installation </H3>


</body>
</html>

Open in new window


Now this is based off using an onchange event in the drop down. It doesn't work right and I don't like it. If I use an onclick event like this:


<button onclick="runPrinterInstall()">Install Your Printer</button>

Open in new window


Would it have the the same effect. With that one I am also unsure how to pass the option ID into the javascript method.

Thank you all so much in advance for any help!
JamiBenson092279Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lalit ChandraCommented:
Jquery made this simple for you.

1.  Just add the jquery and Jquery UI js reference to your page head section.
   
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>

2. add ID attribute to your dropdown  like
    <select id ="PrinterNames ..> ...... </select>

3. Add the code in the script section of your page

$(function() {
     $("#PrinterNames").change(function() {
         var printer = $(this).val();
        var url = "C:\Users\JBenson\Desktop\Printer Scripts\Completed" + printer +".vbs"
        window.open(url,'Start Installation')
     });
});


Hope this will fix up your problem.
0
JamiBenson092279Author Commented:
Thanks for the post Lalit.

I put your code in and it it really isn't doing anything. I assume that this is working off the onchange method in the option box correct?


Thanks again

Jami!
0
Lalit ChandraCommented:
Can you post your page code here ?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

JamiBenson092279Author Commented:
You bet!

 
<html>
<head>
<script script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js">
$(printerInstall() {
     $("#PrinterNames").change(function() {
         var printer = $(this).val();
        var url = "C:\Users\JBenson\Desktop\Printer Scripts\Completed" + printer +".vbs"
        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 name ="PrinterNames" onchange ="printerInstall()">
			<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


Thanks again I really appreciate the help. I so rarely do any scripting and I just had to go pick something difficult lol.

Thanks again!

Jami
0
Lalit ChandraCommented:
Ok. your script section is incorrect and you have't added the id to the select control
So, simple replace all the code from the following code




<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="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>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JamiBenson092279Author Commented:
Sorry about that. I had changed it, but I had a classic case of close without saving and. Once I did change it, properly this time, it now opens another window and gives me an error I attached below.

I guess maybe I should explain what I am trying to do. The path I am referencing, just contains a bunch of script files that trigger the install of drivers. They will eventually reside on a print server with IIS enabled. I just want it to give you the standard box you get saying, open or run.

Is there a better way to do this then the one I started before you helped me?

Thanks again!
0
JamiBenson092279Author Commented:
ooppss! Here is the error

Error Code
0
Lalit ChandraCommented:
Ok. In this post your question regarding the events of Dropdown list, and that has been solved. and here there is On Post should be open only for one question.
So, your first question has been answered. So, Please close this post ,and then start other post with this new question.

Thanks JamiBenson092279
0
JamiBenson092279Author Commented:
I don't believe it was answered.... at all. I asked specifically how to get the page to download the scripts. You didn't answer that. Once you answer that, I will go ahead and award points. If you would like to argue semantics, we can go there too. I don't mean to be rude, but I don't feel it was answered.

Thanks.
0
JamiBenson092279Author Commented:
Expert states they answered the question and strictly in a technical sense, they did. Although the question posed wasn't followed by a question mark, I didn't really get the answer I needed. Thus no points.
0
Lalit ChandraCommented:
No, Don't take it in any other way.If it hurts you then I am extremely sorry...
I don't  had the sense to heart you.

And as your question is concerned, you can try one thing, just host all of your printer files to the local (Intranet) server,then by any specific url you can download that file to the client.So, In this way you can get rid of the Local issue that you r facing.

Hope this will help you better.

Thanks  JamiBenson092279
0
JamiBenson092279Author Commented:
You just didn't answer my question. I'll make sure to give you some points for your time.

The files will be housed on our print server. We are turning IIS on it and hosting a page there. So they will be housed on the intranet.

They are housed on my desktop now until I can prove it works.

I just need a solution for downloading these files via Javascript or Jquery.

I closed the question and re-asked it more specifically.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.