Solved

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

Posted on 2012-03-22
12
226 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
Comment Utility
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
Comment Utility
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
Comment Utility
Can you post your page code here ?
0
 

Author Comment

by:JamiBenson092279
Comment Utility
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
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:JamiBenson092279
Comment Utility
ooppss! Here is the error

Error Code
0
 
LVL 7

Expert Comment

by:Lalit Chandra
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now