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
Solved

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

Posted on 2012-03-22
12
230 Views
Last Modified: 2012-08-13
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!
0
Comment
Question by:JamiBenson092279
  • 7
  • 5
12 Comments
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37758353
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
 

Author Comment

by:JamiBenson092279
ID: 37758508
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
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37758688
Can you post your page code here ?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:JamiBenson092279
ID: 37758700
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
 
LVL 7

Accepted Solution

by:
Lalit Chandra earned 375 total points
ID: 37758766
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
 

Author Comment

by:JamiBenson092279
ID: 37758826
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
 

Author Comment

by:JamiBenson092279
ID: 37758831
ooppss! Here is the error

Error Code
0
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37758861
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
 

Author Comment

by:JamiBenson092279
ID: 37758873
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
 

Author Closing Comment

by:JamiBenson092279
ID: 37758935
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
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37758975
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
 

Author Comment

by:JamiBenson092279
ID: 37758987
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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

856 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