0

I have some ASP code which will display all people in the organisation. I also have it to allow users to select a service area (company) and, using AJAX, it will bring back a list of departments within the company and the user can filter results based on department and service area. I have the following ASP code:

<%@ Language="VBScript"%>
<% response.Buffer = TRUE
'Defines the variables and objects
dim ADUser, RecordList, intOne, intTwo, intThree, companies, service_area, department, arrComp
'Assigns the objComp and objDept variables to Scripting Dictionary objects
%>
<!--#include file="includes/functions.asp"-->
<!--#include file="includes/display.asp"-->
<!--#include file="includes/results.asp"-->
<!--#include file="includes/timer.asp"-->
<h1>Organisational Structure</h1>
<div class="commandspace">
<p class="infotext">The org structure can be viewed with or without staff, indented or left justified.</p>
</div>
</div>
<% 
ADUser = "LDAP://EXAMPLE/OU=Staff,OU=Users,DC=domain,DC=internal"
' Make AD connection and run query
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.provider ="ADsDSOObject"
objCon.Properties("User ID") = "EXAMPLE\User"
objCon.Properties("Password") = "Password"
objCon.Properties("Encrypt Password") = TRUE
objCon.open "Active Directory Provider"
Set objCom = CreateObject("ADODB.Command")
Set objCom.ActiveConnection = objCon 
objCom.CommandText ="select company FROM '"& ADUser &"' where company ='*'" 
Set objRS = objCom.Execute 'Creates an object and runs the LDAP query
Set arrComp = Server.CreateObject("Scripting.Dictionary")
companies = objRS.GetRows()
for intOne = 0 to UBound(companies, 2)
    if Not arrComp.exists(companies(0, intOne)) then
        arrComp.add companies(0, intOne), companies(0, intOne)
    End if
next
response.write "<form action='index.asp?View=Structure' method='POST'>"
response.write "<select id='service_area' name='service_area' onChange='showTeams(this.value)'>"
response.write "<option>Please Select</option>"
For Each item in arrComp.Items
    response.write "<option value='"& Server.URLEncode(item) &"'>" & item & "</option>"  & VBCrlF
next
response.write "</select>"   & VBCrlF
response.write "<span class='structure-spacing'></span>"  & VBCrlF
response.write "<select id='department' name='department'>"
response.write "<option value='-1'>Please Select</option>"
response.write "</select>"  & VBCrlF
response.write "<span class='structure-spacing'></span>"  & VBCrlF
response.write "<input type='submit' name='submit' id='submit'>"  & VBCrlF
response.write "</form>"  & VBCrlF
if request.form("submit")="Submit" then
service_area = request.form("service_area")
department = request.form("department")
if service_area = "Please Select" then 

response.write "<p>Service area cannot be left empty</p>"

end if
     objCom.CommandText ="select company, department, title, cn FROM '"& ADUser &"' where department = '" & department & "' ORDER BY department" 
else
    objCom.CommandText ="select company, department, title, cn FROM '"& ADUser &"' where company ='*' ORDER BY department" 
end if
Set objRS = objCom.Execute 'Creates an object and runs the LDAP query
RecordList = objRS.GetRows()
response.write "<table>"  & VBCrlF
response.write "<thead>"  & VBCrlF
response.write "<tr>"  & VBCrlF
response.write "<th>Service Area</th>"  & VBCrlF
response.write "<th>Department</th>"  & VBCrlF
response.write "<th>Job Title</th>"  & VBCrlF
response.write "<th>Name</th>"  & VBCrlF
response.write "</tr>"  & VBCrlF
response.write "</thead>"  & VBCrlF
response.write "<tbody>"  & VBCrlF
for intThree = 0 to UBound(RecordList,2)
    response.write "<tr class='command'>"  & VBCrlF
    response.write "<td>" & RecordList(3, intThree) & "</td>"  & VBCrlF
    response.write "<td>" & RecordList(2, intThree) & "</td>"  & VBCrlF
    response.write "<td>" & RecordList(1, intThree) & "</td>"  & VBCrlF
    response.write "<td>" & RecordList(0, intThree) & "</td>"  & VBCrlF
response.write "</tr>"  & VBCrlF
next
response.write "</tbody>"  & VBCrlF
response.write "</table>"  & VBCrlF
objRS.Close
objCon.Close
Set objCon = Nothing
Set objCom = Nothing
%>

I have the following AJAX code

    function showTeams(str) {

        if (str=="") {
            document.getElementById("department").innerHTML="";
            return;
        } 

        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                document.getElementById("department").innerHTML=xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","get_teams.asp?q="+str,true);
        xmlhttp.send();
    }    

My problem is that, when the user clicks the submit button in the structure page; Google Chrome will pass the variable through but IE won't and I don't know why

wrichards0
  • 187
  • 4
  • 18
  • Fairly sure the issue here is [`innerHTML`](http://stackoverflow.com/a/2738294/692942), IE is awkward when it comes to using it on certain elements. – user692942 Mar 22 '16 at 10:39
  • Possible duplicate of [Javascript - innerHTML not working with HTML select menus](http://stackoverflow.com/questions/2738254/javascript-innerhtml-not-working-with-html-select-menus) – user692942 Mar 22 '16 at 10:40
  • I was going to use document.getElementById('department').options.add(new Option("value", "text")) but I am not sure how I would use the output of the page that gets the list of departments with this? How do I format the response text – wrichards0 Mar 23 '16 at 09:15

0 Answers0