pickletech
IS-IT--Management
Hello everyone, I am writing an hta to install printers for people. You pick a department from one listbox, then another listbox shows you which printers are in that department. When you select a printer, a description of the printer is displayed. Choose if you want to set it as your default or not and hit install printer. This is working just fine, but there is a problem with my selecting the printer name from the second listbox. Instead of installing the printer that was selected, it installs the first one in that department. I believe this is my problem right here:
Here is the rest of the hta, so you get a better idea of everything.
Thank You,
Pickletech
Code:
SelectedPrinter = form.List2.options[form.List2.selectedIndex].text;
Code:
<html>
<head>
<title>Install Network Printer</title>
<HTA:APPLICATION
ID="objInstallPrinter"
APPLICATIONNAME="Greetings"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal">
</head>
<script language="javascript">
<!--
function setOption(form, index) {
for (var i = 0; i < form.List2.length; i++) {
form.List2.options[i].text = "";
form.List2.options[i].value = "";
}
if (index == 0) {
form.List2.options[0].text = "";
form.List2.options[0].value = "";
}
else if (index == 1) {
form.List2.options[0].text = "pamholpr001";
form.List2.options[0].value = "Accounting LaserJet 8000";
form.List2.options[1].text = "pamholpr006";
form.List2.options[1].value = "T&W LaserJet 4000";
form.List2.options[2].text = "pamholpr007";
form.List2.options[2].value = "LaserJet 4";
form.List2.options[3].text = "pamholpr008";
form.List2.options[3].value = "Copy room LaserJet 4100";
form.List2.options[4].text = "pamholpr010";
form.List2.options[4].value = "Copy room copier";
form.List2.options[5].text = "pamholpr011";
form.List2.options[5].value = "Engineering Color LaserJet 5500";
form.List2.options[6].text = "pamholpr012";
form.List2.options[6].value = "Accounting Color LaserJet 4600";
form.List2.options[7].text = "pamholpr014";
form.List2.options[7].value = "T&W Epson FX 890 Impact Printer";
}
else if (index == 2) {
form.List2.options[0].text = "pamholpr002";
form.List2.options[0].value = "Human Resources LaserJet 4";
}
else if (index == 3) {
form.List2.options[0].text = "pamholpr003";
form.List2.options[0].value = "Maintenance LaserJet 8000";
form.List2.options[1].text = "pamholpr004";
form.List2.options[1].value = "Receiving LaserJet 2200";
}
else if (index == 4) {
form.List2.options[0].text = "pamholpr013";
form.List2.options[0].value = "Process Control LaserJet 4";
}
else if (index == 5) {
form.List2.options[0].text = "pamholpr005";
form.List2.options[0].value = "Production LaserJet 5 (Kurt's Desk)";
form.List2.options[1].text = "pamholpr009";
form.List2.options[1].value = "Quality LaserJet 5si";
form.List2.options[2].text = "pamholpr016";
form.List2.options[2].value = "Prod Maint/Eng Color LaserJet 5100";
form.List2.options[3].text = "pamholpr017";
form.List2.options[3].value = "Color LaserJet 3500";
}
form.List2.selectedIndex = 0;
form.ValueIn2.value = form.List2.options[form.List2.selectedIndex].value;
SelectedPrinter = form.List2.options[form.List2.selectedIndex].text;
}
//-->
</script>
<body>
<form name="ThisForm">
<select name="List1" OnChange="setOption(this.form, this.selectedIndex)">
<option> Choose Location
<option> Front Office
<option> Human Resources
<option> Maintenance
<option> Process Control
<option> Production
</select>
<select name="List2" OnChange="this.form.ValueIn2.value=this.options[this.selectedIndex].value">
<option>
<option>
<option>
<option>
<option>
<option>
<option>
<option>_________________
</select>
<br>
Description: <input name="ValueIn2" size="30">
<br>
<input type="checkbox" Name="DefaultPrinter">Make it default? </input>
<BUTTON style="border:5px outset;width:100px" onClick="InstallPrinter()" >Install Printer</BUTTON>
</form>
<script language="vbscript">
<!--
Sub InstallPrinter()
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\PrintServer\" & SelectedPrinter
If thisform.DefaultPrinter.checked = true Then
objNetwork.SetDefaultPrinter "\\PrintServer\" & SelectedPrinter
End If
End Sub
//-->
</script>
</body>
</html>
Thank You,
Pickletech