|
#1
|
|||
|
|||
|
drop down list populated from a d/base
Can anyone tell me how to create a drop down list populated from a d/base using vbscript or jscript. Can this be done or do you have to use HTML. many thanks in advance |
|
#2
|
|||
|
|||
|
Re: drop down list populated from a d/base
Here's a snippet of code that uses ADO and ASP (JScript) to call a stored procedure which returns in a recordset, names of email domains. That recordset is then iterated through and the drop down list options are created. If you're not using ASP, you can still convert the script to run on the client side. Response.write('<select name="domain" size="1">'); dbConn = Server.CreateObject("ADODB.Connection"); dbConn.Open( Application("db_name"), Application("db_login"), Application("db_pwd") ); dbCmd = Server.CreateObject("ADODB.Command"); dbCmd.ActiveConnection = dbConn; dbCmd.CommandType = 4; dbCmd.CommandText = "user_aliasDomainList"; dbRows = Server.CreateObject("ADODB.Recordset"); dbRows.Open( dbCmd ); while (!dbRows.EOF) { Response.write('<option value="'+dbRows("domain_name").value+'">'+dbRows("domain_name").value+'</option>'); dbRows.moveNext(); } Response.write('</select>'); dbRows.close(); dbConn.close(); -carl "siobhan" <sib121@aol.com> wrote: > >Can anyone tell me how to create a drop down list populated from a d/base >using vbscript or jscript. Can this be done or do you have to use HTML. >many thanks in advance |
|
#3
|
|||
|
|||
|
Re: drop down list populated from a d/base
"siobhan" <sib121@aol.com> wrote: > >Can anyone tell me how to create a drop down list populated from a d/base >using vbscript or jscript. Can this be done or do you have to use HTML. >many thanks in advance Here is some ASP code that uses a variant array that a VB Built component gets from a database to populate a listbox ("<Select>") control on an html form. The code simply steps through the array concatenating a string representing the option tag that will be sent back to the browser via the Response object. Your own solution will depend largely on how you get data out of the database - but here is mine: <select name="SelList" size="20" style="width=100%" > <% If isarray(vData) and not isnull(vData) then for i = 0 to lngMax strID = vData(0,i) strName = vData(1,i) strCompany = vData(2,i) strOption = "<option value=" & strID & ">" & strName & " of " & strCompany response.write strOption next end if %> </select> Good luck |
|
#4
|
|||
|
|||
|
Re: drop down list populated from a d/base
Here's another suggestion using the GetRows method to take a recordset and populate it into a two-dimensional array (which is always the case). This is in VBScript. <% set conn = server.CreateObject("ADODB.Connection") SQL = "select foo, foo_two from tbl_foo" set rs = conn.Execute(SQL) if rs.BOF and rs.EOF then blnRun = False else blnRun = True arrFoo = rs.GetRows() 'returns all records in rs end if rs.close set rs = nothing conn.close set conn = nothing if blnRun then response.write "<select name=""foo"">" & vbcrlf for x = 0 to UBound(arrFoo,2) ' iterates through records response.write "<option value="""&arrFoo(0,x)&""">"&arrFoo(1,x)&"</option>" & vbcrlf next end if %> Have Fun! |
|
#5
|
|||
|
|||
|
Re: drop down list populated from a d/base
Another method which will basically increase the performance is - 1. Use a trigger to write to a file whenever the database table is updated. The text in this file will be of type <select name=x> <option value = 1>One</option> <option value = 2>Two</option> <option value = 3>Three</option> |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|