PDA

Click to See Complete Forum and Search --> : Combo Boxes HELP!!


gilly
Aug 21st, 2000, 05:44 AM
Im trying to populate a single combo box using Javascript. I dont know how to fill the combo box with the data which is stored in my database??(Dynamically)Rather than simply hard coding the data in my ASP page, i want the data to be dynamically built from my VB.

Any ideas?

Mark Sreeves
Aug 21st, 2000, 06:04 AM
try this:



<%@ Language=VBScript %>
<%option explicit%>
<HTML>

<!--
Written by Mark Sreeves
-->

<%


dim conn 'the database conection
dim rst 'recordset
dim strSQL 'SQL string
dim i ' my usual loop counter

'create the connection object
Set Conn = Server.CreateObject("ADODB.Connection")

'open the database
Conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\myDB.mdb")

%>
<BODY>
<form name="frm1">

<SELECT name=select1>

<%

' populate list 1 from the database
strSQL = "SELECT * FROM table1;"
Set rst = Conn.Execute(strSQL)

do while not rst.EOF
'fill the combo box
%>
<OPTION value="<%=rst("id")%>"><%=rst("list1")%>
<%
rst.MoveNext

loop
'close the record set a
rst.close
'and database connection
conn.Close

'free resources...
set conn = nothing
set rst = nothing
%>

</SELECT>


</form>
</BODY>
</HTML>