Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how can i retrieve value from database (MS access) on asp page and give that value to the select tag in html??

i want to give values to the bolded part which is my html page


XML
<html>
<body>


<form action="select.asp" method="post">
<select name="brd"  >
<option>select one</option>
<option value="one">one</option>
<option value="two">two</option>
</select>
<input type="submit" >
</form>
</body>
</html>
Posted
Comments
Sergey Alexandrovich Kryukov 8-Oct-14 15:44pm    
Consider migrating from VBScript to Javascript. Only Javascript is truly standardized and compatible with all software.

Now, the database... Do you really use ASP, or is it ASP.NET (with is not ASP)? In both cases, consider working with the database on the server side only. Doing it on the client side has too many problems: accessibility, security, performance, and a lot more. Better don't do it.

—SA
vihangshah 8-Oct-14 16:11pm    
But i must use asp not asp.net..And as per my need i have to do it on client side...i give you a example
EXAMPLE:-
suppose i took input of brand names from users and that brand names i stored in database now i want that brand names from database to asp page and again i want to display that brnad name on another html page which i fetched from database ....!
but thanks for your suggestion..
PhilLenoir 8-Oct-14 16:11pm    
You are, of course, referring to VBScript on the server, not the client. Is there a reason that you want to do this in ASP and not ASP.Net? It is simpler to do in ASP.Net.

1 solution

It's been a long time since I did any "classic" ASP and I don't have the environment to test this set up, but I think I have the correct syntax. This should be enough to get you going. This file does need to have an ASP extension.
<%@ language="VBSCRIPT" %>
<html>
<body>
<%
    Set con = Server.CreateObject("ADODB.Connection")
    con.Open "MyAccessDB.MDB"
    Set rs = con.Execute("SELECT MyOption FROM MyOptionsLookupTable")
%> 
 
<form action="select.asp" method="post">
<select name="brd">
<option>select one</option>
<% While Not rs.EOF %>
<option value=<% """ & rs("MyOption") & """ %>><% rs("MyOption") %></option>
<% 
    rs.MoveNext
    Wend
    rs.Close
    con.Close 
 %>
</select>
<input type="submit">
</input></form>
</body>
</html>
 
Share this answer
 
v3
Comments
PhilLenoir 8-Oct-14 16:36pm    
CP keeps encoding this, I have to tweak it to correct that encoding ...
It looks good now!
vihangshah 9-Oct-14 7:38am    
the solution help me but the syntax is like <%= rs("MyOption")%> this changes only needed...!!
thank you..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900