The following function builds an HTML Dropdown from an open ADO recordset.
<script language="JScript" type="text/jscript" runat="server">
function buildDropdown(objRS, strValueField, strDisplayField, strSelected)
{
var strReturn = "";
try {
strSelected = ", " + strSelected + ",";
if (typeof(objRS) == "object") {
while (objRS.eof==false) {
var strValue = objRS.fields(strValueField).value;
var strDisplay = objRS.fields(strDisplayField).value;
if (strSelected.indexOf(", " + strValue + ",") == -1 && strSelected.indexOf(", " + strDisplay + ",") == -1 ) {
var strSelect = "";
}
else {
var strSelect = " selected";
}
strReturn += "<option value=\"" + strValue + "\""+ strSelect +">" + strDisplay + "</option>\r\n";
objRS.movenext();
}
}
return strReturn;
}
catch(objError) {
return "<option>ERROR: " + objError.description + "</option>\r\n";
}
}
</script>