Create a DHTML Combo Box

Create a DHTML Combo Box

In Visual Basic, the standard combo box lets you store an Index to its data. For instance, a user would see in the list an employee name but not an associated employeeID. The ID would be stored in the ItemData property of the control. To accomplish this in DHTML, use an ADO recordset to create and populate a combo box on an ASP page. Create the recordset using the standard open methods and while looping through the records add them to the combo box. Include in the loop a counter variable and add 1 to it for each loop through the records. Use the value of the counter as an Index to the value property of the combo box.

   Dim iCnt sSQL, con, adOpenKeyset, adLockReadOnlyDo Until rs.EOF        Set objEntry = Document.createElement("option")        objEntry.Text = rs("Name")        cboEmpNames.Add objEntry        cboEmpNames(iCnt).Value = rs("EmployeeID")        rs.MoveNext        iCnt = iCnt + 1Loop

Now when a user selects the employee name in the list, you will have accessto the value property, which contains the employee ID.

See also  Why ChatGPT Is So Important Today

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist