If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > can we pass a recordset to javascript function ??if yes how

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-01-04, 06:28
Riax Riax is offline
Registered User
 
Join Date: Mar 2004
Posts: 16
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
Reply With Quote
  #2 (permalink)  
Old 04-07-04, 17:54
Wigz Wigz is offline
Registered User
 
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>
Reply With Quote
  #3 (permalink)  
Old 04-07-04, 18:24
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
you might want to add a vbCrLf at the end of the response.write line just to make it look nice.
Reply With Quote
  #4 (permalink)  
Old 04-07-04, 18:32
Wigz Wigz is offline
Registered User
 
Join Date: Feb 2003
Location: Denver, CO
Posts: 34
Yes ... good point rokslide.
Reply With Quote
  #5 (permalink)  
Old 04-07-04, 18:59
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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....
Reply With Quote
  #6 (permalink)  
Old 04-08-04, 06:26
Riax Riax is offline
Registered User
 
Join Date: Mar 2004
Posts: 16
thanks 4 it
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On