Accessing Array On The Client Side

Hello experts!  I'm new to ASP and I'm having problems using the array, generated by GetRows, on the client side.  I have this code on my new.asp page...

<%
...
Dim rsRecords
Set rsRecords = SQLQuery(cnnDB, "SELECT * FROM tblUsers")
   
Dim aArray      
aArray = rsRecords.GetRows

Dim iColumnCount, iRowCount
iRowCount = UBound(aArray,1)
iColumnCount = UBound(aArray,2)

Dim iCtr, jCtr
For iCtr = 0 to iRowCount
      For jCtr = 0 to iColumnCount
            Response.Write aArray(jCtr, iCtr)
      Next
Next
...
%>

On the same new.asp, I have this code...
<script = "Javascript">
<!--
function PopulateTextBoxes()
{
      How do I access the array???
}
-->      
</script>

I'm able to output the contents of the array.  But how do I access that on the javascript?  I'm supposed to populate some textboxes depending on the value selected on a dropdown, so I'm calling the function PopulateTextBoxes on the onchange event.
joelilaoAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
hieloConnect With a Mentor Commented:
>> How do I access the array???
You cannot. The array you are referring to exists only on the server while the script is executing. When the browser finishes loading, the connection between browser and server is closed and the server gets rid of the array. You need to create a copy of the array on the browser by dynamically creating the necessary javascript  code. See below:
<script type="text/Javascript">
<!--
function PopulateTextBoxes()
{
      //How do I access the array???
	 var myArray = new Array();
<%
'...
Dim rsRecords
Set rsRecords = SQLQuery(cnnDB, "SELECT * FROM tblUsers")
    
Dim aArray      
aArray = rsRecords.GetRows
 
Dim iColumnCount, iRowCount
iRowCount = UBound(aArray,1)
iColumnCount = UBound(aArray,2)
 
Dim iCtr, jCtr
For iCtr = 0 to iRowCount
      For jCtr = 0 to iColumnCount
            Response.Write "myArray[myArray.length] = '" & aArray(jCtr, iCtr) & "';";
      Next
Next
'...
%>	 
	 
}
-->      
</script>

Open in new window

0
 
joelilaoAuthor Commented:
Thanks, hielo.  I appreciate the prompt response.  Like I mentioned, I'm very new to ASP & Javascript.  Does this mean I have to write the same code in Javascript?  Will I be able to access my recordset from client side?  I apologize in advance.  Dazed and confused newbie here.
0
 
hieloCommented:
>>Does this mean I have to write the same code in Javascript?
Not sure what you mean by "the same code". On the code I posted, everything in between <% and %> is executed on the server. The browser will see just the output. So the code that the browser will see is going to be similar to:
<script type="text/Javascript">
<!--
function PopulateTextBoxes()
{
      //How do I access the array???
      var myArray = new Array();
      myArray[myArray.length] = "a";
      myArray[myArray.length] = "b";
      myArray[myArray.length] = "c";
}
-->      
</script>

Which basically is copying your recordset to the browser but stored in a javascript array.

>>Will I be able to access my recordset from client side?
No. The recordset exists only on the server while the browser is fetching the data. Once the browser has all the data, the commnunication channel between browser and server is closed and the server throws away the recordset because it does not know if the the same user/browser will be back later. So its safer for it to assume that it will not come back and gets rid of whatever resources (like the recordset) was used to service the user's/browser's last request.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
joelilaoAuthor Commented:
I'm getting a better picture now, hielo.  Thanks.  My only other question is:

<script type="text/Javascript">
<!--
function PopulateTextBoxes()
{
      //How do I access the array???
      var myArray = new Array();
      myArray[myArray.length] = "a";
      myArray[myArray.length] = "b";
      myArray[myArray.length] = "c";
}
-->      
</script>

How do I assign the values to myArray?  When this code is run,

Dim iCtr, jCtr
For iCtr = 0 to iRowCount
      For jCtr = 0 to iColumnCount
            Response.Write aArray(jCtr, iCtr) & vbCrLf
      Next
Next

I get a long string delimited by 'vbCrLf'.  Do I save this long string to a variable and use the Split function?  How do I save this so that I can use it and do the Split function?
0
 
hieloCommented:
>>How do I assign the values to myArray?
Thats EXACTLY what I did for you on my first post! (except I just noticed a typo).
Update this:
Response.Write "myArray[myArray.length] = '" & aArray(jCtr, iCtr) & "';";

with this:
Response.Write "myArray[myArray.length] = '" & aArray(jCtr, iCtr) & "';" & vbCrLf
0
 
joelilaoAuthor Commented:
Oh!  I missed that part!  I'll have to try it out tomorrow and I'll let you know!  Thanks so much, hielo!
0
 
hieloCommented:
OK. Good luck
0
 
joelilaoAuthor Commented:
Hi hielo,

I think I might be having problems with the syntax.  My code now looks like this:

<script language = "Javascript">
<!--
function PopulateTextBoxes()
{
      var myArray = new Array();

<%
      Dim rsRecords
      Set rsRecords = SQLQuery(cnnDB, "SELECT * FROM tblUsers")
   
      Dim aArray      
      aArray = rsRecords.GetRows
   
      Dim iColumnCount, iRowCount
      iRowCount = UBound(aArray,1)
      iColumnCount = UBound(aArray,2)
      
      Dim iCtr, jCtr
      For iCtr = 1 to iRowCount
            For jCtr = 0 to iColumnCount
                  Response.Write "myArray[myArray.length] = '" & aArray(jCtr, iCtr) &"';" & vbCrLf
            Next
      Next
%>
}
//-->
</script>

But the browser doesn't seem to like the code inside <% %>.  I don't get an error when I comment it out.  Please help. :)
0
 
hieloCommented:
>>But the browser doesn't seem to like the code inside <% %>.  
The file that contains the script above should be saved with a ".asp" extension, not html. It sounds like the browser is literally getting all the code you posted. The stuff between  <% %> is meant to excute on the server, not the browser.
0
 
joelilaoAuthor Commented:
The script is inside a file named new.asp.  Maybe the code's inside the wrong tag???  
0
 
hieloCommented:
You could try posting your whole script so I can take a look!
0
 
joelilaoAuthor Commented:
Here you go, hielo.  Thanks for taking time.

<%@ LANGUAGE="VBScript" %>
<%
  Option Explicit
  'Buffer the response, so Response.Expires can be used
  Response.Buffer = TRUE
%>


<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

  <!--       #include file = "../public.asp" -->
  <%
    Dim cnnDB, sid
    Set cnnDB = CreateCon
    sid = GetSid
   
  %>

<head>
<title><%=lang(cnnDB, "HelpDesk")%> - <%=lang(cnnDB, "NewProblem")%></title>
<link rel="stylesheet" type="text/css" href="../default.css">

</head>
<body>

<%

      
      ' Check if user has permissions for this page
      Call CheckRep(cnnDB, sid)

  Dim blnSubmitNew, strSubmitResults
  If Cint(Request.Form("save")) = 1 Then
    blnSubmitNew = True
  Else
    blnSubmitNew = False
  End If
      
  ' ==============================================
  ' Save problem
  If blnSubmitNew Then
    ' Get the information from the form fields
    Dim uid, uemail, uphone, ulocation, ulocation2, category, department, title, description, upager
    Dim priority, status, rep, time_spent, solution, entered_by, uselectid, kb

    uselectid = Request.Form("uselectid")
    uid = Request.Form("uid")
    uemail = Request.Form("uemail")
    uphone = Request.Form("uphone")
    upager = Request.Form("upager")
    ulocation = Cint(Request.Form("ulocation"))
    ulocation2 = Request.Form("ulocation2")
    category = Cint(Request.Form("category"))
    department = Request.Form("department")
    title = Request.Form("title")
    description = Request.Form("description")
    priority = Cint(Request.Form("priority"))
    status = Cint(Request.Form("status"))
    rep = Cint(Request.Form("rep"))
    time_spent = Cint(Request.Form("time_spent"))
    solution = Request.Form("solution")

    If Request.Form("kb") = "on" Then
      kb = 1
    Else
      kb = 0
    End If

    ' Check for required fields (uemail, category, department, title, description)
    If uselectid <> 0 then
      uid = usr(cnnDB, uselectid, "uid")
      uemail = usr(cnnDB, uselectid, "email1")
      uphone = usr(cnnDB, uselectid, "phone")
      upager = usr(cnnDB, uselectid, "pager")
      ulocation = usr(cnnDB, uselectid, "location1")
      ulocation2 = usr(cnnDB, uselectid, "location2")
      department = usr(cnnDB, uselectid, "department")
    Else
      If Len(uid)=0 Then
        Call DisplayError(1, lang(cnnDB, "UserName"))
      End if

      if uemail = Cfg(cnnDB, "BaseEmail") Then
        Call DisplayError(1, lang(cnnDB, "EMailAddress"))
      End if
    End If

    if category = 0 Then
      Call DisplayError(1, lang(cnnDB, "Category"))
    End if

      if (ulocation = 0) And (uselectid = 0) Then
      Call DisplayError(1, lang(cnnDB, "Location"))
    End if
   
    if Len(uphone)=0 Then
      Call DisplayError(1, lang(cnnDB, "Phone"))
    End if
     
    if (department = 0) And (uselectid = 0) Then
      Call DisplayError(1, lang(cnnDB, "Department"))
    End if

    if Len(title)=0 Then
      Call DisplayError(1, lang(cnnDB, "Title"))
    Elseif Len(title) > 50 Then
      title = Trim(title)
      title = Left(title, 50)
    End if

    if Len(description)=0 Then
      Call DisplayError(1, lang(cnnDB, "Description"))
    End if

    if (status=Cfg(cnnDB, "CloseStatus")) and (Len(solution)=0) Then
      Call DisplayError(1, lang(cnnDB, "Solution"))
    End if

    ' Get missing variables to enter problem
    Dim id

    Dim dname, depRes
    Set depRes = SQLQuery(cnnDB, "SELECT dname FROM departments WHERE department_id=" & Request.Form("department"))
    dname = depRes("dname")
   
    Dim locname, locRes
    Set locRes = SQLQuery(cnnDB, "SELECT locname FROM locations WHERE location_id=" & Request.Form("ulocation"))
    locname = locRes("locname")

    Dim cname, catRes
    Set catRes = SQLQuery(cnnDB, "SELECT cname, rep_id FROM categories WHERE category_id=" & Request.Form("category"))
    cname = catRes("cname")

    entered_by = sid

    ' Get the problem ID number then immediately update it
    id = GetUnique(cnnDB, "problems")

    ' Convert strings to valid SQL strings
    On Error Resume Next
    uphone = Replace(uphone,"'","''")
    upager = Replace(upager,"'","''")
    ulocation2 = Replace(ulocation2,"'","''")
    'ulocation = Replace(ulocation,"'","''")
    title = Replace(title,"'","''")
    description = Replace(description,"'","''")
    solution = Replace(solution,"'","''")
    On Error Goto 0

    ' All data is present
    ' Write problem into database
    Dim probStr

    ' If status is closed, then include the closed date/time
      If status = Cfg(cnnDB, "CloseStatus") Then
        probStr = "INSERT INTO problems (id, uid, uemail, uphone, upager, ulocation, ulocation2, " & _
        "category, department, title, description, priority, status, start_date, rep, time_spent, " & _
        "close_date, entered_by, solution, kb) " & _
        "VALUES (" & id & ",'" & uid & "','" & uemail & "','" & uphone & "','" & upager & "'," & _
        ulocation & ",'" & ulocation2 & "'," & category & "," & department & ",'" & title & "','" & _
        description & "'," & priority & "," & status & "," & SQLDate(Now, lhdAddSQLDelim) & "," & rep & "," & time_spent & _
        "," & SQLDate(Now, lhdAddSQLDelim) & "," & entered_by & ",'" & solution & "', " & kb & ")"
      Else
        probStr = "INSERT INTO problems (id, uid, uemail, uphone, upager, ulocation, ulocation2, " & _
        "category, department, title, description, priority, status, start_date, rep, time_spent, " & _
        "entered_by, solution, kb) " & _
        "VALUES (" & id & ",'" & uid & "','" & uemail & "','" & uphone & "','" & upager & "'," & _
        ulocation & ",'" & ulocation2 & "'," & category & "," & department & ",'" & title & "','" & _
        description & "'," & priority & "," & status & "," & SQLDate(Now, lhdAddSQLDelim) & "," & rep & "," & time_spent & _
        "," & entered_by & ",'" & solution & "'," & kb & ")"
      End If

      Dim problemRes
      Set problemRes = SQLQuery(cnnDB, probStr)

    ' Get support rep information for later
      Dim remail, repRes
      Set repRes = SQLQuery(cnnDB, "SELECT * FROM tblUsers WHERE sid=" & rep)
      remail = repRes("email1")

    ' Send mail to the user and support rep if the problem
    ' was not closed at the time of being entered.
    Dim strSubject, strBody

    If status<>Cfg(cnnDB, "CloseStatus") Then
      ' Send mail to the user
      If Not (Request.Form("noemail")="on") Then
        Call eMessage(cnnDB, "usernew", id, uemail)
      End If

      ' Send mail to the Rep
      Call eMessage(cnnDB, "repnew", id, remail)

      'Page Rep if enabled
      If (priority >= Cfg(cnnDB, "EnablePager")) And (Len(Usr(cnnDB, rep, "email2")) > 0) Then
        Call eMessage(cnnDB, "reppager", id, Usr(cnnDB, rep, "email2"))
      End If

    End If

    ' If the problem is closed when being entered, send
    ' a different email to the user.
    If status=Cfg(cnnDB, "CloseStatus") Then
      If Not (Request.Form("noemail")="on") Then
        ' Send mail to the user
        Call eMessage(cnnDB, "userclose", id, uemail)
      End If
    End If
    strSubmitResults = Lang(cnnDB, "Problem") & " " & id & " " & Lang(cnnDB, "hasbeenentered") & "."
  End If
      
  ' ==============================================

  Dim rstDepList, rstCatList, rstStatList, rstPriList, rstRepList, rstLocList
%>
<form action="new.asp" method="POST">
<input type="hidden" name="save" value="1">

<div align="center">
  <table class="Normal">
    <tr>
      <td colspan="2" align="right">
        <em>*</em> = <%=lang(cnnDB, "Required")%>
      </td>
    </tr>
    <tr class="Head1">
      <td colspan="2">
        <%=lang(cnnDB, "SubmitANewProblem")%>
      </td>
    </tr>
    <% If blnSubmitNew Then %>
      <tr class="Head2">
        <td colspan="2">
          <div align="center">
            <% = strSubmitResults %>
          </div>
        </td>
      </tr>
    <% End If %>
    <tr class="Body1">
      <td valign="top" align="center" width="50%">
        <table class="narrow" border="0">
          <tr>
            <td align="center" colspan="2">
              <b><%=lang(cnnDB, "ContactInformation")%></b>
            </td>
          </tr>
          <tr>
            <td>
              <b><%=lang(cnnDB, "UserName")%>:</b>
            </td>
            <td>
              <input type="text" name="uid" size="20"><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b><%=lang(cnnDB, "EMail")%>:</b>
            </td>
            <td>
              <input type="text" name="uemail" size="20" value="<% = Cfg(cnnDB, "BaseEmail") %>"><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b><%=lang(cnnDB, "Department")%>:</b>
            </td>
            <td>
              <SELECT NAME="department">
              <OPTION VALUE="0" SELECTED><%=lang(cnnDB, "SelectDepartment")%></OPTION>
              <%
                Set rstDepList = SQLQuery(cnnDB, "SELECT * From departments WHERE department_id > 0 ORDER BY dname ASC")
                If not rstDepList.EOF Then
                Do While Not rstDepList.EOF
              %>
              <OPTION VALUE="<% = rstDepList("department_id")%>">
              <% = rstDepList("dname") %></OPTION>

              <%             rstDepList.MoveNext
                Loop
                End If
              %>
              </SELECT><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b><%=lang(cnnDB, "Location")%>:</b>
            </td>
            <td>
              <SELECT NAME="ulocation">
              <OPTION VALUE="0" SELECTED><%=lang(cnnDB, "SelectLocation")%></OPTION>
              <%
                Set rstLocList = SQLQuery(cnnDB, "SELECT * From locations WHERE location_id > 0 ORDER BY locname ASC")
                If not rstLocList.EOF Then
                Do While Not rstLocList.EOF
              %>
              <OPTION VALUE="<% = rstLocList("location_id")%>">
              <% = rstLocList("locname") %></OPTION>

              <%             rstLocList.MoveNext
                Loop
                End If
              %>
              </SELECT><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b><%=lang(cnnDB, "Room")%>:</b>
            </td>
            <td>
               <input type="text" name="ulocation2" size="20">
            </td>
          </tr>
          <tr>
            <td>
              <b><%=lang(cnnDB, "Phone")%>:</b>
            </td>
            <td>
               <input type="text" name="uphone" size="20"><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b><%=lang(cnnDB, "Pager")%>:</b>
            </td>
            <td>
               <input type="text" name="upager" size="20">
            </td>
          </tr>
          <%
          If cfg(cnnDB, "useSelectUser") = 1 Then
          %>
            <tr>
              <td colspan="2">
                <div align="center">
                  <b>--- <%=lang(cnnDB, "Or")%> ---</b>
                </div>
              </td>
            </tr>
            <tr>
              <td>
                <b><%=lang(cnnDB, "SelectUser")%>:</b>
              </td>
              <td>
                <select name="uselectid" onchange="PopulateTextBoxes();">
                  <option value="0" selected><%=lang(cnnDB, "SelectUser")%></option>
                  <%
                    ' Get list of users to diplay
                    Dim rstUser
                    Set rstUser = SQLQuery(cnnDB, "SELECT * FROM tblUsers WHERE sid > 0 ORDER BY uid ASC")
                    If not rstUser.EOF Then
                      Do While Not rstUser.EOF
                      %>
                        <option value="<% = rstUser("sid")%>">
                        <% = rstUser("uid") %>&nbsp;(<% = rstUser("fname") %>)
                        </option>
                      <%
                      rstUser.MoveNext
                      Loop
                    End If
                  %>
                </select>
              </td>
            </tr>
          <%
          end if
          %>
        </table>
      </td>
      <td valign="top">
        <table class="narrow" border="0">
          <tr>
            <td align="center" colspan="2">
              <b><%=lang(cnnDB, "Classification")%></b>
            </td>
          </tr>
          <tr>
            <td>
              <b><%=lang(cnnDB, "Category")%>:</b>
            </td>
            <td>
              <SELECT NAME="category">
              <OPTION VALUE="0" SELECTED><%=lang(cnnDB, "SelectCategory")%></OPTION>
              <%
                Set rstCatList = SQLQuery(cnnDB, "SELECT * From categories WHERE category_id > 0 ORDER BY cname ASC")
                If Not rstCatList.EOF Then
                Do While Not rstCatList.EOF
              %>
              <OPTION VALUE="<% = rstCatList("category_id")%>">
              <% = rstCatList("cname") %></OPTION>

              <%             rstCatList.MoveNext
                Loop
                End If
              %>
              </SELECT><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b><%=lang(cnnDB, "Status")%>:</b>
            </td>
            <td>
              <SELECT NAME="status">
                <%
                  Set rstStatList = SQLQuery(cnnDB, "SELECT * From status WHERE status_id > 0 ORDER BY status_id ASC")
                  If Not rstStatList.EOF Then
                  Do While Not rstStatList.EOF
                  If rstStatList("status_id") = Cfg(cnnDB, "DefaultStatus") Then
                  %>
                  <OPTION VALUE="<% = rstStatList("status_id")%>" SELECTED>
                  <% = rstStatList("sname") %></OPTION>
                  <% Else %>
                  <OPTION VALUE="<% = rstStatList("status_id")%>">
                  <% = rstStatList("sname") %></OPTION>

                <%       End If
                  rstStatList.MoveNext
                  Loop
                  End If
                %>
              </SELECT><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b><%=lang(cnnDB, "Priority")%>:</b>
            </td>
            <td>
              <SELECT NAME="priority">
              <%
                Set rstPriList = SQLQuery(cnnDB, "SELECT * From priority WHERE priority_id > 0 ORDER BY priority_id ASC")
                If Not rstPriList.EOF Then
                Do While Not rstPriList.EOF
                If rstPriList("priority_id") = Cfg(cnnDB, "DefaultPriority") Then
                %>
                <OPTION VALUE="<% = rstPriList("priority_id")%>" SELECTED>
                <% = rstPriList("pname") %></OPTION>
                <% Else %>
                <OPTION VALUE="<% = rstPriList("priority_id")%>">
                <% = rstPriList("pname") %></OPTION>

              <%       End If
                rstPriList.MoveNext
                Loop
                End If
              %>
              </SELECT><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b><%=lang(cnnDB, "AssignTo")%>:</b>
            </td>
            <td>
              <SELECT NAME="rep">
              <%
                Set rstRepList = SQLQuery(cnnDB, "SELECT * From tblUsers WHERE IsRep = 1 AND RepAccess <> 2 AND sid > 0 ORDER BY uid ASC")
                If Not rstRepList.EOF Then
                Do While Not rstRepList.EOF
                If rstRepList("sid") = sid Then
                %>
                <OPTION VALUE="<% = rstRepList("sid")%>" SELECTED>
                <% = rstRepList("uid") %></OPTION>
                <% Else %>
                <OPTION VALUE="<% = rstRepList("sid")%>">
                <% = rstRepList("uid") %></OPTION>

              <%       End If
                rstRepList.MoveNext
                Loop
                End If
              %>
              </SELECT><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b><%=lang(cnnDB, "TimeSpent")%>:</b>
            </td>
            <td>
              <input type="text" size="4" name="time_spent" value="0">(<%=lang(cnnDB, "minutes")%>)
            </td>
          </tr>
        </table>
      </td>
    <tr class="Head2">
      <td colspan="2">
        <%=lang(cnnDB, "ProblemInformation")%>:
      </td>
    </tr>
    <tr class="Body1">
      <td colspan="2">
        <b><%=lang(cnnDB, "Title")%>:</b><em>*</em><br />
        <input type="text" name="title" size="50">
        <p>
        <b><%=lang(cnnDB, "Description")%>:</b><em>*</em><br />
        <textarea rows="8" cols="80" name="description"></textarea>
      </td>
    </tr>
    <tr class="Head2">
      <td colspan="2">
        <%=lang(cnnDB, "Solution")%>:
      </td>
    </tr>
    <tr class="Body1">
      <td colspan="2">
        <textarea rows="8" cols="80" name="solution"></textarea>
        <% If Cfg(cnnDB, "EnableKB") <> 0 Then %>
          <input type="checkbox" name="kb">&nbsp;<%=lang(cnnDB, "EnterinKnowledgeBase")%>
        <% End If %>
      </td>
    </tr>
    <tr class="Head2">
      <td colspan="2" align="center">
        <% If Cfg(cnnDB, "EmailType") <> 0 Then %>
          <input type="checkbox" name="noemail">&nbsp;<%=lang(cnnDB, "Dontsendemailtouser")%>
        <% End If %>
        <p>
        <input type="submit" value="<%=lang(cnnDB, "SubmitProblem")%>" name="B1">&nbsp;<input type="reset" value="<%=lang(cnnDB, "ClearForm")%>" name="B2">
      </td>
    </tr>
  </table>
</div>
</form>

<%
      
      ' close record sets
      rstCatList.Close
      rstDepList.Close
      rstLocList.Close
      rstStatList.Close
      rstPriList.Close
      rstRepList.Close

      Call DisplayFooter(cnnDB, sid)
      cnnDB.Close

%>

<script language = "Javascript">
<!--
function PopulateTextBoxes()
{
      var myArray = new Array();

<%
      Dim rsRecords
    Set rsRecords = SQLQuery(cnnDB, "SELECT * FROM tblUsers")
   
    Dim aArray      
      aArray = rsRecords.GetRows
   
      Dim iColumnCount, iRowCount
      iRowCount = UBound(aArray,1)
      iColumnCount = UBound(aArray,2)
      
      Dim iCtr, jCtr
      For iCtr = 1 to iRowCount
            For jCtr = 0 to iColumnCount
                  Response.Write "myArray[myArray.length] = '" & aArray(jCtr, iCtr) &"';" & vbCrLf
            Next
      Next
%>
}
//-->
</script>

</body>

</html>
0
 
hieloCommented:
>>But the browser doesn't seem to like the code inside
The posted code look OK. Are you loading the page via the browser directly from the server? If you are using a software like Dreamweaver (which should really be called "Major Nightmare Weaver"), then  don't use that to Preview your page. Look at your page directly via the browser.
Other than that the only suggestion I can make is to try:
...
      Call DisplayFooter(cnnDB, sid)
      cnnDB.Close

Response.Write("<script type='text/Javascript'><!-- ")
%>
...

Instead of:
...
 Call DisplayFooter(cnnDB, sid)
      cnnDB.Close

%>
...

Since ASP does have a server-side <SCRIPT> tag.
0
 
joelilaoAuthor Commented:
I'm previewing it via the browser directly from the server.  I'll see what I can do.
0
 
joelilaoAuthor Commented:
Hi hielo,

I moved the javascript part inside the <head> tags, and that seemed to have solved the problem.  So now my code looks like this:

<script language=javascript>
<!--
      function PopulateUserInfo(paramID)
      {
      var myArray = new Array();
      <%
   
   
    Dim rsRecords
    Set rsRecords = SQLQuery(cnnDB, "SELECT * FROM tblUsers")
   
    Dim aArray      
      aArray = rsRecords.GetRows
   
      Dim iColumnCount, iRowCount
      iColumnCount = UBound(aArray,1)
      iRowCount = UBound(aArray,2)
      
      rsRecords.Close
      Set rsRecords = Nothing

      Dim iCtr, jCtr
      For iCtr = 1 to iRowCount
            For jCtr = 0 to iColumnCount
                  Response.Write "myArray[myArray.length] = '" & aArray(jCtr, iCtr) &"';" & vbCrLf
            Next
      Next
      
  %>
            
      }
//-->
</script>

So after the '%>' and before the '}', should I be able to do this:?

var i=0;

i = <%iRowCount%>

OR

if myArray(0,3) = 3 ...

I get an error when I do something like this.  Wrong syntax?
0
 
hieloCommented:
>> i = <%iRowCount%>
You probably meant:
i = <%=iRowCount%>

But to answer your question, anything between '%>' and '}' is NOT executing on the server. Instead it is just being sent to the browser as "plain text" BUT you can always switch into "server context" by putting <%%> again. That's why I thing you meant:
...
%>
   var i = <%=iRowCount%>;        
      }

If I understand your logic, you are trying to know how many rows were returned by the query. If so, the answer lies in the total number of elements stored in myArray. So, instead of:
  var i = <%=iRowCount%>;
you can simply use plain javascript:
  var i = myArray.length;
0
 
joelilaoAuthor Commented:
I got that working.  Thanks.  My problem now is that it gives me an 'Object Expected' error.  If I take out this line,

Response.Write "myArray[myArray.length] = '" & aArray(jCtr, iCtr) &"';" & vbCrLf

then I don't get the error.  But of course, I need this line of code! :)

Any ideas?

Here's the whole code.  I didn't change it and all of a sudden I get the 'Object Expected' error!

<script language=javascript>
<!--
      function PopulateUserInfo(paramID)
      {
      var myArray = new Array();
      <%
    Dim rsRecords
    Set rsRecords = SQLQuery(cnnDB, "SELECT * FROM tblUsers")
   
    Dim aArray      
      aArray = rsRecords.GetRows
   
      Dim iColumnCount, iRowCount
      iColumnCount = UBound(aArray,1)
      iRowCount = UBound(aArray,2)
      
      rsRecords.Close
      Set rsRecords = Nothing

      Dim iCtr, jCtr
      For iCtr = 1 to iRowCount
            For jCtr = 0 to iColumnCount
                  Response.Write "myArray[myArray.length] = '" & aArray(jCtr, iCtr) & "';" & vbCrLf
            Next
      Next      
      
  %>
        
      }
//-->
</script>
0
 
hieloCommented:
>>'Object Expected'
This is typically reported by the browser, not the server. So you need to examine the generated HTML. Post the GENERATED html.  Your Response.Write is OK. Typically that error indicates that you are calling a nonexisting function OR misspelled a function OR are trying to dereference a non existing object or you are trying to dereference a non-existing property of an object.
0
 
joelilaoAuthor Commented:
I did some tinkering.  Now I get the 'Expected ;' error.  Here's the generated HTML:

Thanks!

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

  <!--
  Liberum Help Desk, Copyright (C) 2000-2001 Doug Luxem
  Liberum Help Desk comes with ABSOLUTELY NO WARRANTY
  Please view the license.html file for the full GNU General Public License.

  Filename: new.asp
  Date:     $Date: 2002/08/28 15:30:54 $
  Version:  $Revision: 1.51.2.1.2.2 $
  Purpose:  This page displays the form used for entering new problems.
  -->

 

<head>
<title>Help Desk - New Problem</title>
<link rel="stylesheet" type="text/css" href="../default.css">


<script language=javascript>
<!--
      function PopulateUserInfo(paramID)
      {
      var myArray = new Array();
      myArray[myArray.length] = '1';
myArray[myArray.length] = 'mresnick';
myArray[myArray.length] = 'g#minor7-9';
myArray[myArray.length] = 'Mike Resnick';
myArray[myArray.length] = 'michael.resnick@ucsf.edu';
myArray[myArray.length] = '';
myArray[myArray.length] = '415-206-6143';
myArray[myArray.length] = '0';
myArray[myArray.length] = '';
myArray[myArray.length] = '0';
myArray[myArray.length] = '1';
myArray[myArray.length] = '1/25/2008 2:44:35 PM';
myArray[myArray.length] = '1/30/2008 9:37:24 AM';
myArray[myArray.length] = '0';
myArray[myArray.length] = 'Mike';
myArray[myArray.length] = 'Resnick';
myArray[myArray.length] = '0';
myArray[myArray.length] = '';
myArray[myArray.length] = '';
myArray[myArray.length] = '';
myArray[myArray.length] = '';
myArray[myArray.length] = '';
myArray[myArray.length] = '0';
myArray[myArray.length] = '1/25/2008 2:44:35 PM';
myArray[myArray.length] = '1';
myArray[myArray.length] = '0';
myArray[myArray.length] = 'mike's pager';
myArray[myArray.length] = '2';
myArray[myArray.length] = 'sbaker';
myArray[myArray.length] = 'sbaker';
myArray[myArray.length] = 'Susan Baker';
myArray[myArray.length] = 'susan.baker@ucsf.edu';
myArray[myArray.length] = '';
myArray[myArray.length] = '415-206-6546';
myArray[myArray.length] = '0';
myArray[myArray.length] = '';
myArray[myArray.length] = '0';
myArray[myArray.length] = '1';
myArray[myArray.length] = '1/25/2008 2:45:35 AM';
myArray[myArray.length] = '2/7/2008 3:56:01 PM';
myArray[myArray.length] = '0';
myArray[myArray.length] = 'Susan';
myArray[myArray.length] = 'Baker';
myArray[myArray.length] = '0';
myArray[myArray.length] = '';
myArray[myArray.length] = '';
myArray[myArray.length] = '';
myArray[myArray.length] = '';
myArray[myArray.length] = '';
myArray[myArray.length] = '0';
myArray[myArray.length] = '';
myArray[myArray.length] = '';
myArray[myArray.length] = '0';
myArray[myArray.length] = '';
myArray[myArray.length] = '3';
myArray[myArray.length] = 'dave leonard';
myArray[myArray.length] = 'dleonard';
myArray[myArray.length] = 'David Leonard';
myArray[myArray.length] = 'david.leonard@ucsf.edu';
myArray[myArray.length] = '';
myArray[myArray.length] = '415-206-4935';
myArray[myArray.length] = '0';
myArray[myArray.length] = '';
myArray[myArray.length] = '1';
myArray[myArray.length] = '1';
myArray[myArray.length] = '1/28/2008 11:53:04 AM';
myArray[myArray.length] = '1/28/2008 11:53:04 AM';
myArray[myArray.length] = '0';
myArray[myArray.length] = 'David';
myArray[myArray.length] = 'Leonard';
myArray[myArray.length] = '0';
myArray[myArray.length] = '';
myArray[myArray.length] = '';
myArray[myArray.length] = '';
myArray[myArray.length] = '';
myArray[myArray.length] = '';
myArray[myArray.length] = '0';
myArray[myArray.length] = '1/28/2008 11:53:03 AM';
myArray[myArray.length] = '1';
myArray[myArray.length] = '0';
myArray[myArray.length] = '';
myArray[myArray.length] = '4';
myArray[myArray.length] = 'test user';
myArray[myArray.length] = 'test';
myArray[myArray.length] = 'Test User';
myArray[myArray.length] = 'testuser@ucsf.edu';
myArray[myArray.length] = '';
myArray[myArray.length] = '415-test';
myArray[myArray.length] = '1';
myArray[myArray.length] = '7F';
myArray[myArray.length] = '1';
myArray[myArray.length] = '1';
myArray[myArray.length] = '1/30/2008 10:03:20 AM';
myArray[myArray.length] = '1/30/2008 10:03:20 AM';
myArray[myArray.length] = '0';
myArray[myArray.length] = 'Test';
myArray[myArray.length] = 'User';
myArray[myArray.length] = '0';
myArray[myArray.length] = '';
myArray[myArray.length] = '';
myArray[myArray.length] = '';
myArray[myArray.length] = '';
myArray[myArray.length] = '';
myArray[myArray.length] = '0';
myArray[myArray.length] = '1/30/2008 10:03:20 AM';
myArray[myArray.length] = '1';
myArray[myArray.length] = '0';
myArray[myArray.length] = 'test's pager';

        
      }
-->
</script>

</head>
<body>


<form action="new.asp" method="POST">
<input type="hidden" name="save" value="1">

<div align="center">
  <table class="Normal">
    <tr>
      <td colspan="2" align="right">
        <em>*</em> = Required
      </td>
    </tr>
    <tr class="Head1">
      <td colspan="2">
        Submit A New Problem
      </td>
    </tr>
   
    <tr class="Body1">
      <td valign="top" align="center" width="50%">
        <table class="narrow" border="0">
          <tr>
            <td align="center" colspan="2">
              <b>Contact Information</b>
            </td>
          </tr>
          <tr>
            <td>
              <b>User Name:</b>
            </td>
            <td>
              <input type="text" name="uid" size="20"><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b>E-Mail:</b>
            </td>
            <td>
              <input type="text" name="uemail" size="20" value="@ucsf.edu"><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b>Department:</b>
            </td>
            <td>
              <SELECT NAME="department">
              <OPTION VALUE="0" SELECTED>Select Department</OPTION>
             
              <OPTION VALUE="1">
              Administration</OPTION>

             
              <OPTION VALUE="9">
              Bridge to Wellness</OPTION>

             
              <OPTION VALUE="16">
              CASARC</OPTION>

             
              <OPTION VALUE="32">
              CCSF</OPTION>

             
              <OPTION VALUE="13">
              Child & Adolescent Services</OPTION>

             
              <OPTION VALUE="14">
              Child Trauma Research Project</OPTION>

             
              <OPTION VALUE="17">
              Citywide Case Management</OPTION>

             
              <OPTION VALUE="18">
              Community Focus</OPTION>

             
              <OPTION VALUE="21">
              Consultation Liaison Service</OPTION>

             
              <OPTION VALUE="8">
              Crisis Resolution Team</OPTION>

             
              <OPTION VALUE="22">
              ED Case Management</OPTION>

             
              <OPTION VALUE="2">
              Finance</OPTION>

             
              <OPTION VALUE="23">
              Health Access Program</OPTION>

             
              <OPTION VALUE="3">
              Human Resources</OPTION>

             
              <OPTION VALUE="15">
              Infant Parent Program</OPTION>

             
              <OPTION VALUE="4">
              Information Technology Services</OPTION>

             
              <OPTION VALUE="6">
              Inpatient Service</OPTION>

             
              <OPTION VALUE="31">
              Masson</OPTION>

             
              <OPTION VALUE="28">
              Munoz</OPTION>

             
              <OPTION VALUE="24">
              Neuropsychology Service</OPTION>

             
              <OPTION VALUE="19">
              Opiate Treatment Programs</OPTION>

             
              <OPTION VALUE="7">
              Psychiatric Emergency Services</OPTION>

             
              <OPTION VALUE="25">
              Psychosocial Medicine Clinic</OPTION>

             
              <OPTION VALUE="30">
              Shumway</OPTION>

             
              <OPTION VALUE="29">
              Sorensen</OPTION>

             
              <OPTION VALUE="20">
              Stimulant Treatment Programs</OPTION>

             
              <OPTION VALUE="5">
              Training</OPTION>

             
              <OPTION VALUE="27">
              Trauma Recovery Center</OPTION>

             
              <OPTION VALUE="26">
              Traumatic Brain Injury</OPTION>

             
              <OPTION VALUE="33">
              Unknown</OPTION>

             
              </SELECT><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b>Bldg.:</b>
            </td>
            <td>
              <SELECT NAME="ulocation">
              <OPTION VALUE="0" SELECTED>Select Location</OPTION>
             
              <OPTION VALUE="6">
              Offsite - 1460 Pine Street</OPTION>

             
              <OPTION VALUE="7">
              Offsite - 2727 Mariposa Street</OPTION>

             
              <OPTION VALUE="9">
              Offsite - 3180 18th Street</OPTION>

             
              <OPTION VALUE="8">
              Offsite - 982 Mission Street</OPTION>

             
              <OPTION VALUE="10">
              Other</OPTION>

             
              <OPTION VALUE="2">
              SFGH - Building 20</OPTION>

             
              <OPTION VALUE="3">
              SFGH - Building 80</OPTION>

             
              <OPTION VALUE="1">
              SFGH - Building 9</OPTION>

             
              <OPTION VALUE="4">
              SFGH - Building 90</OPTION>

             
              <OPTION VALUE="5">
              SFGH - Trailer 9</OPTION>

             
              </SELECT><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b>Room:</b>
            </td>
            <td>
               <input type="text" name="ulocation2" size="20">
            </td>
          </tr>
          <tr>
            <td>
              <b>Phone:</b>
            </td>
            <td>
               <input type="text" name="uphone" size="20"><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b>Pager:</b>
            </td>
            <td>
               <input type="text" name="upager" size="20">
            </td>
          </tr>
         
            <tr>
              <td colspan="2">
                <div align="center">
                  <b>--- Or ---</b>
                </div>
              </td>
            </tr>
            <tr>
              <td>
                <b>Select User:</b>
              </td>
              <td>
                <select name="uselectid" onchange="PopulateUserInfo(this.value)">
                  <option value="0" selected>Select User</option>
                 
                        <option value="3">
                        dave leonard&nbsp;(David Leonard)
                        </option>
                     
                        <option value="1">
                        mresnick&nbsp;(Mike Resnick)
                        </option>
                     
                        <option value="2">
                        sbaker&nbsp;(Susan Baker)
                        </option>
                     
                        <option value="4">
                        test user&nbsp;(Test User)
                        </option>
                     
                </select>
              </td>
            </tr>
         
        </table>
      </td>
      <td valign="top">
        <table class="narrow" border="0">
          <tr>
            <td align="center" colspan="2">
              <b>Classification</b>
            </td>
          </tr>
          <tr>
            <td>
              <b>Category:</b>
            </td>
            <td>
              <SELECT NAME="category">
              <OPTION VALUE="0" SELECTED>Select Category</OPTION>
             
              <OPTION VALUE="33">
              City - invision printing</OPTION>

             
              <OPTION VALUE="34">
              City - MAC address registration</OPTION>

             
              <OPTION VALUE="32">
              City - port activation</OPTION>

             
              <OPTION VALUE="18">
              Email - cannot access</OPTION>

             
              <OPTION VALUE="17">
              Email - create account</OPTION>

             
              <OPTION VALUE="19">
              Email - other</OPTION>

             
              <OPTION VALUE="14">
              Hardware - install PC</OPTION>

             
              <OPTION VALUE="12">
              Hardware - keyboard</OPTION>

             
              <OPTION VALUE="11">
              Hardware - monitor</OPTION>

             
              <OPTION VALUE="13">
              Hardware - mouse</OPTION>

             
              <OPTION VALUE="15">
              Hardware - move PC</OPTION>

             
              <OPTION VALUE="16">
              Hardware - other</OPTION>

             
              <OPTION VALUE="10">
              Hardware - PC</OPTION>

             
              <OPTION VALUE="38">
              Laoner - other</OPTION>

             
              <OPTION VALUE="35">
              Loaner - laptop</OPTION>

             
              <OPTION VALUE="36">
              Loaner - PC</OPTION>

             
              <OPTION VALUE="37">
              Loaner - projector</OPTION>

             
              <OPTION VALUE="5">
              Network - cannot connect</OPTION>

             
              <OPTION VALUE="6">
              Network - drive missing</OPTION>

             
              <OPTION VALUE="4">
              Network - modify account</OPTION>

             
              <OPTION VALUE="3">
              Network - new account</OPTION>

             
              <OPTION VALUE="9">
              Network - other</OPTION>

             
              <OPTION VALUE="7">
              Network - restore file</OPTION>

             
              <OPTION VALUE="8">
              Network - VPN access</OPTION>

             
              <OPTION VALUE="22">
              Printer - cannot print</OPTION>

             
              <OPTION VALUE="20">
              Printer - install</OPTION>

             
              <OPTION VALUE="21">
              Printer - jam/repair</OPTION>

             
              <OPTION VALUE="23">
              Printer - other</OPTION>

             
              <OPTION VALUE="1">
              Reset password - network</OPTION>

             
              <OPTION VALUE="2">
              Reset password - PC</OPTION>

             
              <OPTION VALUE="24">
              Software - install</OPTION>

             
              <OPTION VALUE="31">
              Software - other</OPTION>

             
              <OPTION VALUE="29">
              Software - problems with DPH app</OPTION>

             
              <OPTION VALUE="26">
              Software - problems with MS Office</OPTION>

             
              <OPTION VALUE="25">
              Software - problems with OS</OPTION>

             
              <OPTION VALUE="28">
              Software - problems with Psych app</OPTION>

             
              <OPTION VALUE="30">
              Software - problems with UC app</OPTION>

             
              <OPTION VALUE="27">
              Software - problems with web browser</OPTION>

             
              <OPTION VALUE="40">
              Training - MS Office</OPTION>

             
              <OPTION VALUE="39">
              Training - OS</OPTION>

             
              <OPTION VALUE="42">
              Training - other software</OPTION>

             
              <OPTION VALUE="41">
              Training - Psych app</OPTION>

             
              </SELECT><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b>Status:</b>
            </td>
            <td>
              <SELECT NAME="status">
               
                  <OPTION VALUE="1" SELECTED>
                  OPEN</OPTION>
                 
                  <OPTION VALUE="100">
                  CLOSED</OPTION>

               
              </SELECT><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b>Priority:</b>
            </td>
            <td>
              <SELECT NAME="priority">
             
                <OPTION VALUE="1" SELECTED>
                LOW</OPTION>
               
                <OPTION VALUE="2">
                HIGH</OPTION>

             
              </SELECT><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b>Assign To:</b>
            </td>
            <td>
              <SELECT NAME="rep">
             
                <OPTION VALUE="3">
                dave leonard</OPTION>

             
                <OPTION VALUE="1">
                mresnick</OPTION>

             
                <OPTION VALUE="2" SELECTED>
                sbaker</OPTION>
               
                <OPTION VALUE="4">
                test user</OPTION>

             
              </SELECT><em>*</em>
            </td>
          </tr>
          <tr>
            <td>
              <b>Time Spent:</b>
            </td>
            <td>
              <input type="text" size="4" name="time_spent" value="0">(minutes)
            </td>
          </tr>
        </table>
      </td>
    <tr class="Head2">
      <td colspan="2">
        Problem Information:
      </td>
    </tr>
    <tr class="Body1">
      <td colspan="2">
        <b>Title:</b><em>*</em><br />
        <input type="text" name="title" size="50">
        <p>
        <b>Description:</b><em>*</em><br />
        <textarea rows="8" cols="80" name="description"></textarea>
      </td>
    </tr>
    <tr class="Head2">
      <td colspan="2">
        Solution:
      </td>
    </tr>
    <tr class="Body1">
      <td colspan="2">
        <textarea rows="8" cols="80" name="solution"></textarea>
       
          <input type="checkbox" name="kb">&nbsp;Enter in Knowledge Base
      </td>
    </tr>
    <tr class="Head2">
      <td colspan="2" align="center">
       
          <input type="checkbox" name="noemail">&nbsp;Don't send email to user
        <p>
        <input type="submit" value="Submit Problem" name="B1">&nbsp;<input type="reset" value="Clear Form" name="B2">
      </td>
    </tr>
  </table>
</div>
</form>

<p><div align="center"><a href="http://10.84.24.100/helpdesktest/user">User Menu</a> | <a href="http://10.84.24.100/helpdesktest/rep">Rep Menu</a> | <a href="http://10.84.24.100/helpdesktest/logoff.asp">Log Off</a></div></p><p><hr width="500">
<div align="center"><font size="-1"><a href="http://www.liberum.org">Liberum Help Desk</a>, Copyright (C) 2001 Doug Luxem. Please view the <a href="http://10.84.24.100/helpdesktest/license.html">license</a>.</font></div></p>

</body>

</html>
0
 
hieloCommented:
Your database fields contain apostrophes. So it generates these:
myArray[myArray.length] = 'mike's pager';
myArray[myArray.length] = 'test's pager';

That is not valid javascript syntax. You have an unmatched apostrophy. The javascript engine "thinks" that the value ends at "mike" (instead of "mike's pager") and "test" (instead of "test's pager") .

Update the line generating that code to this:
Response.Write "myArray[myArray.length] = '" & Replace(aArray(jCtr, iCtr),"'","\'") & "';" & vbCrLf
0
 
joelilaoAuthor Commented:
Thanks, hielo!  Awesome! :)
0
 
joelilaoAuthor Commented:
Thanks, hielo!
0
All Courses

From novice to tech pro — start learning today.