Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss
Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

JavaScript population of ASP drop down

2 views
Skip to first unread message

philip...@cogeco.ca

unread,
Jan 9, 2008, 2:14:24 PM1/9/08
to
First, my apologies for a newbie question that may have been answered
before - my JavaScript skills lag behind my VB experience.

I am trying to populate an drop down control with the recordset
results of an ADODB connection to a Access DB. The database/recordset
portion seems to be working fine. However, I'm not clear how to write
the Select <options>.

BACKGROUND
* I have modularized the DB open + close.... global var the
variables

function openDB() {
strConnection = "UID=;pwd=;DSN=reports;";
objConn = new ActiveXObject("ADODB.Connection");
objConn.open(strConnection);
objRS = new ActiveXObject("ADODB.Recordset");
}
function closeDB() {
objRS.Close();
objConn.Close();
}

* The onChange even triggers the following:
openDB();
strSqlData ="SELECT fld_example from tbl_example";
objRS.open(strSqlData, objConn);
while(!objRS.EOF) {
........ OK so far....how do I get the recordset
sequentially into the select?
<OPTION value="<%= rs("fld_example")%>"><%=
rs.Fields("fld_example")%></option>
<%
rs.movenext
Loop
%>
....??? VB how do wite that into the form using JS?

Any advice or examples would be greatly appreciated (other than RTFM).

Phil Morgan


// document.getElementById("year").[getElementById("year").length]=
new Option ("display string " + i, "value " + i);
// }
closeDB();
break;

McKirahan

unread,
Jan 9, 2008, 4:50:05 PM1/9/08
to
<philip...@cogeco.ca> wrote in message
news:699d68ce-f2a6-4d3e...@e10g2000prf.googlegroups.com...

Is the recordset "objRS" or "rs"?

I usually construct the string comletely:

var opts = "";
while(!objRS.EOF) {
opts += "<option value=" + objRS("fld_example") + ">" +
objRS.Fields("fld_example") + "</option>"
objRS.movenext
}

before using it:

<select>
<%=opts%>
</select>

Also, I usually use VBScript (instead of JScript) with ASP.

(Note sure what that code was after your signature.)


0 new messages