Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2004
    Posts
    16

    Unanswered: can we pass a recordset to javascript function ??if yes how

    hi, can anybody tell me how can we pass a recordset to a fuction in javascript.
    plz do respond

  2. #2
    Join Date
    Feb 2003
    Location
    Denver, CO
    Posts
    34
    Loop over the recordset and fill a JavaScript array with ASP.

    <script language="JavaScript">
    items = new Array();
    <%
    IntCount = 0
    While NOT rs.EOF
    Response.Write "items[" & IntCount & "] = '" & rs("record") & "';" 'Use singles inside doubles if item is type string
    IntCount = IntCount + 1
    rs.MoveNext
    Wend
    %>
    </script>

  3. #3
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    you might want to add a vbCrLf at the end of the response.write line just to make it look nice.

  4. #4
    Join Date
    Feb 2003
    Location
    Denver, CO
    Posts
    34
    Yes ... good point rokslide.

  5. #5
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    I think you can do something like this also...
    Code:
    <script language="JavaScript">
    items = new Array(
    <%
    IntCount = 0
    While NOT rs.EOF
    Response.Write "'" & rs("record") & "'," 'Use singles inside doubles if item is type string
    rs.MoveNext
    Wend
    %>
    );
    </script>
    which is less code and generates less Javascript....

    Not sure if the syntax is right but basically you are initalising the javascript array at the same time as declaring it.... I don't have my handy books here to check it out....

  6. #6
    Join Date
    Mar 2004
    Posts
    16
    thanks 4 it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •