Link to home
Start Free TrialLog in
Avatar of JamiBenson092279
JamiBenson092279Flag for United States of America

asked on

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!
Avatar of Lalit Chandra
Lalit Chandra
Flag of India image

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.
Avatar of JamiBenson092279

ASKER

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!
Can you post your page code here ?
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
ASKER CERTIFIED SOLUTION
Avatar of Lalit Chandra
Lalit Chandra
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!
ooppss! Here is the error

User generated image
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
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.
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.
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
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.