1

我正在编写一个小型 .HTA 应用程序来捕获用户的职位、电话号码和地址并将它们上传到 AD。我正在使用一小块 VB 从 AD 中提取信息并填充一些文本框(这本身可以工作)和一些 Javascript 来填充一个下拉框,该下拉框根据选择的内容填充一些其他文本框(这有效通过它自己)。还有一小部分 VB 将填充他们在单击更新时登录的计算机对象的“管理者”字段。

我遇到了麻烦,我将两段代码与 HTML 表单结合起来,我认为问题要么是我看不到的简单错字,要么我无法同时使用 Javascript 和 VB,因为它们都会尝试填充相同的文本框?

.HTA 如下,尽可能多地注释:

<!--Utility for Users to update their Active Directory Accounts-->

<title>User Directory Updater</title>
<HTA:APPLICATION 
    ID="objTSBITGuys" 
    APPLICATIONNAME="Directory Update"
    SCROLL="No"
    SINGLEINSTANCE="yes"
    WINDOWSTATE="normal"
    BORDER="dialog"
    CAPTION="e-Assistant"
>
</head>

<!--Load VB Script-->

<SCRIPT Language="VBScript">

<!--Create Window-->

Sub Window_Onload
window.resizeTo 375,700

<!--Begin Run-->

<!--Connect to Active Directory-->

Set objADSysInfo = CreateObject("ADSystemInfo")
strUser = objADSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
OptionLists
strMyDC = "MyDC" & "/"
Set objADSysInfo = CreateObject("ADSystemInfo")
strUser = objADSysInfo.UserName
Set objItem = GetObject("LDAP://" & strMyDC & strUser)
On Error Resume Next

<!--Get Active Directory attributes to modify-->
<!--strATTRIBUTENAME = objItem.Get("LDAP NAME")-->

strDisplayName = objItem.Get("displayName")
strTitle = objItem.Get("title")
strMobile = objItem.Get("mobile")
strOffice = objItem.Get("physicalDeliveryOfficeName")
strStreetAddress = objItem.Get("streetAddress")
strState = objItem.Get("st")
strZIP = objItem.Get("postalCode")
strTelephoneNumber = objItem.Get("telephoneNumber")
strFax = objItem.Get("otherFacsimileTelephoneNumber")
strWww = objItem.Get("wWWHomePage")

<!--Map Attributes to Text Boxes-->

Txt_Disp.Value = strDisplayName
Txt_Title.Value = strTitle
Txt_Mobile.Value = strMobile
Txt_Office.Value = strOffice
Txt_Street.Value = strStreetAddress
Txt_State.Value = strState
Txt_Zip.Value = strZIP
Txt_Tel.Value = strTelephoneNumber
Txt_Fax.Value = strFax
Txt_Www.Value = strWww

End Sub

Sub OptionLists

End Sub

<!--Save changes to Active Directory when Update button is pressed-->

Sub Update
Set objADSysInfo = CreateObject("ADSystemInfo")
strUser = objADSysInfo.UserName
Set objUser = GetObject("LDAP://MyDC" & strUser)
On Error Resume Next

<!--Commented out to prevent changes - objUser.Put "displayName", Txt_Disp.Value-->
objUser.Put "title", Txt_Title.Value
objUser.Put "mobile", Txt_Mobile.Value
objUser.Put "physicalDeliveryOfficeName", Txt_Office.Value
objUser.Put "streetAddress", Txt_Street.Value
objUser.Put "st", Txt_State.Value
objUser.Put "postalCode", Txt_Zip.Value
objUser.Put "telephoneNumber", Txt_Tel.Value
objUser.Put "otherFacsimileTelephoneNumber", Txt_Fax.Value
objUser.Put "wWWHomePage", Txt_Www.Value

objUser.SetInfo

MsgBox "Thank you, your information has been saved."

<!--Populate the "Managed By" field for the computer the user is currently logged on to-->

Set objSysInfo = CreateObject("ADSystemInfo") 
Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)  
objComputer.Put "managedBy", objSysInfo.Username 
objComputer.Put "Description", objSysInfo.Username
objComputer.SetInfo

<!--End Run-->

End Sub

Sub PrintThis
    Window.Print()
End Sub

</SCRIPT>

<!--Begin HTML for page layout-->

<script type="text/javascript">

// Format of Names()
// Name,Office,Addr1,Addr2,Addr3,Phone,Www

var StoreDetails = [
['Select a Name','','','','','','','','',''],
['Name','Name','Addr1','Addr2','Addr3','Phone','Fax','www'],
['Name1','Name1','Addr1-1','Addr2-1','Addr3-1','Phone1','Fax1','www1'],
['Name1','Name1','Addr1-2','Addr2-2','Addr3-2','Phone2','Fax2','www2'],
['Name1','Name1','Addr1-3','Addr2-3','Addr3-3','Phone3','Fax3','www3'],
['Name1','Name1','Addr1-4','Addr2-4','Addr3-4','Phone4','Fax4','www4'],
['Name1','Name1','Addr1-5','Addr2-5','Addr3-5','Phone5','Fax5','www5'],
['Name1','Name1','Addr1-6','Addr2-6','Addr3-6','Phone6','Fax6','www6'],
['Name1','Name1','Addr1-7','Addr2-7','Addr3-7','Phone7','Fax7','www7'],
['Name1','Name1','Addr1-8','Addr2-8','Addr3-8','Phone8','Fax8','www8'],
['Name1','Name1','Addr1-9','Addr2-9','Addr3-9','Phone9','Fax9','www9'],
['Name1','Name1','Addr1-10','Addr2-10','Addr3-10','Phone10','Fax10','www10'],
['Name1','Name1','Addr1-11','Addr2-11','Addr3-11','Phone11','Fax11','www11'],
['Name1','Name1','Addr1-12','Addr2-12','Addr3-12','Phone12','Fax12','www12'],
['Name1','Name1','Addr1-13','Addr2-13','Addr3-13','Phone13','Fax13','www13'],
['Name1','Name1','Addr1-14','Addr2-14','Addr3-14','Phone14','Fax14','www14'],
['Name1','Name1','Addr1-15','Addr2-15','Addr3-15','Phone15','Fax15','www15'],
['Name1','Name1','Addr1-16','Addr2-16','Addr3-16','Phone16','Fax16','www16'],
['Name1','Name1','Addr1-17','Addr2-17','Addr3-17','Phone17','Fax17','www17'],
['Name1','Name1','Addr1-18','Addr2-18','Addr3-18','Phone18','Fax18','www18'],
['Name1','Name1','Addr1-19','Addr2-19','Addr3-19','Phone19','Fax19','www19'],
['Name1','Name1','Addr1-20','Addr2-20','Addr3-20','Phone20','Fax20','www20'],
['Name1','Name1','Addr1-21','Addr2-21','Addr3-21','Phone21','Fax21','www21'],
['Name1','Name1','Addr1-22','Addr2-22','Addr3-22','Phone22','Fax22','www22'],
['Name1','Name1','Addr1-23','Addr2-23','Addr3-23','Phone23','Fax23','www23'],
['Name1','Name1','Addr1-24','Addr2-24','Addr3-24','Phone24','Fax24','www24'],
['Name1','Name1','Addr1-25','Addr2-25','Addr3-25','Phone25','Fax25','www25'],
['Name1','Name1','Addr1-26','Addr2-26','Addr3-26','Phone26','Fax26','www26'],
['Name1','Name1','Addr1-27','Addr2-27','Addr3-27','Phone27','Fax27','www27'],
['Name1','Name1','Addr1-28','Addr2-28','Addr3-28','Phone28','Fax28','www28'],
['Name1','Name1','Addr1-29','Addr2-29','Addr3-29','Phone29','Fax29','www29'],
['Name1','Name1','Addr1-30','Addr2-30','Addr3-30','Phone30','Fax30','www30'],
['Name1','Name1','Addr1-31','Addr2-31','Addr3-31','Phone31','Fax31','www31'],
['Name1','Name1','Addr1-32','Addr2-32','Addr3-32','Phone32','Fax32','www32'],
['Name1','Name1','Addr1-33','Addr2-33','Addr3-33','Phone33','Fax33','www33'],
['Name1','Name1','Addr1-34','Addr2-34','Addr3-34','Phone34','Fax34','www34'],
['Name1','Name1','Addr1-35','Addr2-35','Addr3-35','Phone35','Fax35','www35'],
['Name1','Name1','Addr1-36','Addr2-36','Addr3-36','Phone36','Fax36','www36'],
['Name1','Name1','Addr1-37','Addr2-37','Addr3-37','Phone37','Fax37','www37'],
['Name1','Name1','Addr1-38','Addr2-38','Addr3-38','Phone38','Fax38','www38'],
['Name1','Name1','Addr1-39','Addr2-39','Addr3-39','Phone39','Fax39','www39'],
['Name1','Name1','Addr1-40','Addr2-40','Addr3-40','Phone40','Fax40','www40'],
['Name1','Name1','Addr1-41','Addr2-41','Addr3-41','Phone41','Fax41','www41'],
['Name1','Name1','Addr1-42','Addr2-42','Addr3-42','Phone42','Fax42','www42'],
['Name1','Name1','Addr1-43','Addr2-43','Addr3-43','Phone43','Fax43','www43'],
['Name1','Name1','Addr1-44','Addr2-44','Addr3-44','Phone44','Fax44','www44'],
['Name1','Name1','Addr1-45','Addr2-45','Addr3-45','Phone45','Fax45','www45'],
['Name1','Name1','Addr1-46','Addr2-46','Addr3-46','Phone46','Fax46','www46'],
['Name1','Name1','Addr1-47','Addr2-47','Addr3-47','Phone47','Fax47','www47'],
['Name1','Name1','Addr1-48','Addr2-48','Addr3-48','Phone48','Fax48','www48'],
['Name1','Name1','Addr1-49','Addr2-49','Addr3-49','Phone49','Fax49','www49'],
['Name1','Name1','Addr1-50','Addr2-50','Addr3-50','Phone50','Fax50','www50'],
['Name1','Name1','Addr1-51','Addr2-51','Addr3-51','Phone51','Fax51','www51'],
['Name1','Name1','Addr1-52','Addr2-52','Addr3-52','Phone52','Fax52','www52'],
['Name1','Name1','Addr1-53','Addr2-53','Addr3-53','Phone53','Fax53','www53'] // Note: no comma
];
function Setup(TA) {
var str = "<select id='Store' onchange='StoreInfo()'>";
for (var i=0; i<StoreDetails.length; i++) {
str += '<option value="'+StoreDetails[i].join('|')+'">'+StoreDetails[i][0]+'</option>';
}
str +='</select>';
document.write(str);

}
function StoreInfo() {
var sel = document.getElementById('Store').selectedIndex;
var tmp = []; tmp.push(sel);
for (var i=1; i<9; i++) { tmp.push(StoreDetails[sel][i]); }
document.getElementById('Txt_Office').value = tmp[1];
document.getElementById('Txt_Street').value = tmp[2];
document.getElementById('Txt_State').value = tmp[3];
document.getElementById('Txt_ZIP').value = tmp[4];
document.getElementById('Txt_Tel').value = tmp[5];
document.getElementById('Txt_Fax').value = tmp[6];
document.getElementById('Txt_Www').value = tmp[7];
}
</script>

<!--End Script Begin HTML-->

</head>
<body>
        <form name="theform" onsubmit="CheckForm()">
  <table width=100% border="0">
                <tr><td width="80"><img src="sw-logo-en.png" alt="" width="90" height="105" /></td><td width="300"><p align="center"><font size="2" face=Verdana color=#333333><strong>User Directory Updater</strong></font></p>
  <p><font size="2" face=Verdana color=#333333>Welcome to UDU, This utility provides you with the ability to manage your details held within IT's systems.</font></p></td></tr>

            <tr><td><font size="2" face=Verdana color=#333333>Name:</font></td><td><font size="2" face=Verdana color=#333333><input type="text" name="Txt_Disp" style="color:888;" onblur"inputBlur(This)" size="30" /></font></td></tr>
             <tr><td><font size="2" face=Verdana color=#333333>Job Title:</font></td><td><font size="2" face=Verdana color=#333333><input type="text" name="Txt_Title" size="30" /></font></td></tr>
             <tr><td><font size="2" face=Verdana color=#333333>Mobile:</font></td><td><font size="2" face=Verdana color=#333333><input type="text" name="Txt_Cell" size="30" /></font></td></tr>

            <tr><td><font size="2" face=Verdana color=#333333>Name1:</font></td><td><script type="text/javascript">Setup();</script></td></tr>
            <tr><td><font size="2" face=Verdana color=#333333>Address:</font></td><td><input type="text" id="Txt_Office" size="30" value=""></td></tr>
            <tr><td>&nbsp;</td><td><input type="text" id="Txt_Street" size="30" value=""></td></tr>
            <tr><td>&nbsp;</td><td><input type="text" id="Txt_State" size="30" value=""></td></tr>
            <tr><td><font size="2" face=Verdana color=#333333>Postcode:</font></td><td><input type="text" id="Txt_ZIP" size="30" value=""></td></tr>
            <tr><td><font size="2" face=Verdana color=#333333>Telehone:</font></td><td><input type="text" id="Txt_Tel" size="30" value=""></td></tr>
            <tr><td><font size="2" face=Verdana color=#333333>Fax:</font></td><td><input type="text" id="Txt_Fax" size="30" value=""></td></tr>
            <tr><td>&nbsp;</td><td><input type="hidden" id="Txt_Www" size="30" value=""></td></tr>
            <tr><td colspan="2"><div align="center"><input id=runbutton  class="button" type="button" value="Update" name="UpdateInf"  onclick="Update" /></div></td></tr>
            <tr><td height="62" colspan="2"><p><font size="1" face=Verdana color=#333333>Please enter your details  and click the &quot;Submit&quot; button, allow 12 hours for your signature to update and 24 hours for these changes to be reflected in the Global Address List.<br />
  <br />
  *<a href="http://selfservice/">Contact IT support</a> to change your account name or if you require  assistance with this utility.</font></p></td></tr>
  </table>
    </form>
</body>
</html>

任何指点都感激不尽。

4

1 回答 1

1
Txt_Disp.Value = strDisplayName
Txt_Title.Value = strTitle
Txt_Mobile.Value = strMobile
Txt_Office.Value = strOffice
Txt_Street.Value = strStreetAddress
Txt_State.Value = strState
Txt_Zip.Value = strZIP
Txt_Tel.Value = strTelephoneNumber
Txt_Fax.Value = strFax
Txt_Www.Value = strWww

我猜你需要用来getElementById访问这些字段,例如

document.getElementById("Txt_Disp").Value = strDisplayName

简单地使用 ID 可能在 JScript 中有效,但在 VBS 中无效。

于 2011-12-18T02:10:39.107 回答