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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Jscript

Status
Not open for further replies.

CFB

Programmer
Jan 11, 2001
74
US
Hi. I'm creating a navigation bar with popup submenus for my website using jscript. I want to create the menus dynamically based on results from a database. I know how to pull the result list back with vbscript and know how to create the popup menus with jscript, but I don't know how to make the two work together. Should I query the database using jscript and avoid using vbscript for this portion of my project? Thanks in advance for the help.
 
"Should I query the database using jscript"

Unless you are using server-side jscript... and I don't think that's what you mean... you won't be able to access the database from the client-side. Even if you could, I don't think that you would want your database connection details, such as user name and password, being sent to the client.

You could simply output the database results to an array in jscript, then build the menus based on the results of the array... something like this I supposed:
Code:
<%
dim r, i
set r = server.createobject(&quot;adodb.recordset&quot;)
r.open &quot;select ID, name from table where ...whatever...&quot;, &quot;...connection details...&quot;
%>
<script language=jscript>
var menu_array=new Array(1);
menu_array[0] = new Array(<% = r.RecordCount %>);
menu_array[1] = new Array(<% = r.RecordCount %>);
<%
for i = 0 to r.recordcount-1
response.write &quot;menu_array[0][i]=&quot; & r(&quot;ID&quot;) & &quot;;&quot;
response.write &quot;menu_array[1][i]=&quot; & r(&quot;name&quot;) & &quot;;&quot;
r.movenext
next
r.close
set r = nothing
%>
</script>
Well that was written off of the top of my head and it's not efficient or error-free... but you get the point. By doing something like above, you would have ASP output an array full of values for your client-side jscript to work with.

TheInsider
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top