Link to home
Start Free TrialLog in
Avatar of wobbled
wobbledFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ASP dataset - load into Javascript Array

I have a simple ASP recordset being returned that I create a table from with a checkbox in the final column.

At the same time I wish to store the City_ID and City_Name values into a multi dimensional array in Javascript.

Once the values are into the array I will be looking at a method of searching that array for City_Name.  So eg if I typed in Paris - as long as the item was in the array - I would get returned the ID for Paris (which I would then automatically check the checkbox for that ID)

So in short - I need to add the Recordset items of City_ID and City_Name into a 2 dimensional array.
Then I need a method or example of how I would search for a string in that array based on City_Name that would return the corresponding City ID.

I can do this on a VB side easily but Javascript is not really my key area so your help is appreciated
<table class="data" id="tblTrips" sort="yes">
              	<tr>
                    <th>ID</th><th>Location</th><th>Select</th>
                </tr>
                <% 		
                    Do While Not RsX.EOF 
                %>
                
                <tr>
                  <td width="75"><% Response.Write RsX("City_ID") %> </td>
                    <td><% Response.Write RsX("City_Name") %> </td>            
                    <td align="center">
                      <input name="<% Response.Write RsX("City_Name") %>" type="checkbox" id="<% Response.Write "cbx_" & RsX("City_ID")%>" value="<% Response.Write RsX("City_ID") %>" onclick="javascript:loopForm();" />
                    </td>
               </tr>
                   
               <% 
                    RsX.MoveNext		
                    Loop
               %>
                                        
              </table>

Open in new window

Avatar of Sven
Sven
Flag of Germany image

Maybe this little example will help you. Never used it.
<html><head><title>Test</title>
</head><body>
<script type="text/javascript">
var Customer = new Array();
 
Customer[0] = new Object();
Customer[0]["Lastname"] = "Miller";
Customer[0]["Firstname"] = "Jack";
Customer[0]["City"] = "New York City";
 
Customer[1] = new Object();
Customer[1]["Lastname"] = "Schneider";
Customer[1]["Firstname"] = "Bob";
Customer[1]["City"] = "Dallas";
 
for (var i = 0; i < Customer.length; i++) {
  document.write("<dl><dt>Customer " + (i + 1) + "<\/dt>");
  for (var CustomerProperty in Customer[i])
    document.write("<dd>" + CustomerProperty + ": " + Customer[i][CustomerProperty] + "<\/dd>");
  document.write("<\/dl>");
}
</script>
</body></html>

Open in new window

Avatar of wobbled

ASKER

unfortunately that doesn't really cover how I add the array values from the asp.
ASKER CERTIFIED SOLUTION
Avatar of Sven
Sven
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wobbled

ASKER

Used this as the basis and developed what you put from there.  Cheers