?
Solved

ASP dataset - load into Javascript Array

Posted on 2009-07-02
4
Medium Priority
?
463 Views
Last Modified: 2012-05-07
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

0
Comment
Question by:wobbled
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:Sven
ID: 24761789
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

0
 
LVL 17

Author Comment

by:wobbled
ID: 24761817
unfortunately that doesn't really cover how I add the array values from the asp.
0
 
LVL 11

Accepted Solution

by:
Sven earned 1500 total points
ID: 24761844
As for my example:
<script type="text/javascript">
var Customer = new Array();
<%
i = 0
Do While Not objRs.EOF
  %>
  Customer[<% = i %>] = new Object();
  Customer[<% = i %>]["Lastname"] = <% = objRs("Lastname") %>;
  Customer[<% = i %>]["Firstname"] = <% = objRs("Firstname") %>;
  Customer[<% = i %>]["City"] = <% = objRs("City") %>;
  <%
  objRs.MoveNext
  i = i + 1
 
Loop
%>
</script>

Open in new window

0
 
LVL 17

Author Closing Comment

by:wobbled
ID: 31599109
Used this as the basis and developed what you put from there.  Cheers
0

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question