Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selection from Dynamic Dropdown populates a textbox

Status
Not open for further replies.

jontout

Technical User
Dec 29, 2006
95
GB
Hi.

I'm not overly sure on the process I'm working is best practice or even overly viable, I've been wracking my brains and could do with some input.

I'm redesigning an aspect of our intranet, replacing a look up from a semi-managed SQL database and querying Active Directory, pulling out Departments and Managers by OU into an ASP Dictionary to populate a dropdown list of Departments. When a user selects the relevant Department from the DDL, the Manager text field auto populates.

Course, this would be 'easy' with SQL as you could build the DDL via a query and cross reference with a SQL lookup. BUT I have to move away from SQL and rely on AD.

Here's the code for the Dictionary adding, someone might find a use for it, and this works a treat.
Code:
strRootOu="LDAP://[b]insert your domain details here[/b]"
	
	Set objDict = Server.CreateObject("Scripting.Dictionary")

    if (strRootOu="") then 
	Set rootDSE = GetObject("LDAP://RootDSE")
    Set domain = GetObject("LDAP://" & rootDSE.Get("defaultNamingContext"))
    else
	Response.Write "<BR>Reading AD - 03<BR>"
    Set domain = GetObject(strRootOu)
    end if

	enumerateOU domain.ADsPath, 0

    Set domain = Nothing
    Set rootDSE = Nothing
		
	response.write "<P><hr>"
	response.write "<BR>objDict.Count = " & objDict.Count & "<BR>"
Code:
    Set ou = GetObject(strCN)
    OU.Filter = Array("organizationalUnit")
    For Each Thing In ou

'            response.write "<BR>" & Thing.ou 
			fGet = (InStr(Thing.managedBy,","))

			if fGet<1 then
			else '	response.Write " - " & mid(Thing.managedBy,4,(fGet-4))
			oKey = Thing.ou
			oLock = mid(Thing.managedBy,4,(fGet-4))
			objDict.add oKey, oLock
			end if
			
            OUtest = enumerateOU(Thing.ADsPath, intLocalLevel)

    Next
    Set ou = Nothing

and this populates the DDL

Code:
    <td class="supphead">Department:</td>
    <td><select name="Dept" size="1" style="width:40%" onChange="textValue()">
      <option selected></option>

<%
allKeys = objDict.Keys 
for i = 0 to objDict.Count - 1
MyKey = allKeys(i)
	if MyKey="Bristol" then
	Else Response.Write"<option>" & MyKey & "</option>"
	End If
next

'set objDict=nothing
%>

I'm playing with the JavaScript OnChange function at the moment, but don't want to spend ages with this if I'm doing something wrong further up the page.

Anyone had a similar project, offer a better way of doing things? I'd be interested in hearing some thoughts.

Cheers,

Jon
 
Thanks Foxbox, however I'm not looking to populate a quantity of dropdowns, just one text box based on the selection made from an AD sourced ASP Dictionary populated dropdown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top