Home   Free Applications   Code Snippets   Fun Stuff 
 
 You are here: Home > Code Snippets > ASP
Register   Login  

 
Site Navigation


Print Print this page
Email E-mail this page
Bookmark Add to Favorites

 
Build HTML Dropdown - JScript Version

Posted by on Friday, October 17, 2003 (EST)

The following function builds an HTML Dropdown from an open ADO recordset.

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>

Add Your Comment



Top