Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

recordset into javascript array?

Status
Not open for further replies.

Ovatvvon

Programmer
Feb 1, 2001
1,514
US
Anyone know the proper way to set a recordset object into a javascript array to dynamically change the contents of fields by the user selection?

We have a page where the user will select between two options (radio buttons)...and depending on which one they click on, it will either load the latest records data into the page's form fields from one table in the database, or from the other table.

I want to make it so as soon as they click on either radio button, and/or click back to the other one, it will display that selections data within the form.

I forget the proper way to set an array offhand in javascript, and I'm pretty sure that upon setting the array within the javascript that you could assign a recordset (or a server side array) to the javascript's value. Just need someone to refresh my memmory.

Thanks in advance! -Ovatvvon :-Q
 
Anyone? Anyone? Buler? Buler? -Ovatvvon :-Q
 
To make a javascript array, just declare it like so:

var myArray = new Array(<%=rs.recordCount%>);

we went ahead and set it equal to the number of your records there, too. AKA

var myArray = new Array(10) // or whatever

You can then go through and set the values like so:

<script language=javascript>
<%
dim i
i = 0
while not rs.eof
response.write(&quot;myArray[&quot; & i & &quot;] = &quot; & rs(&quot;theField&quot;) & &quot;;&quot; & vbcr)
rs.movenext
i = i + 1
wend
%>
</script>

So that the resulting code comes out looking something along these lines:

<script language=javascript>
myArray[0] = 1;
myArray[1] = 2;
myArray[2] = 3;

// and so on

</script>

:)
paul
penny.gif
penny.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top