Jan 05

Build a Select/Combobox in HTML Function (buildSelect)

Builds an HTML select inputbox from a dataset. This script relies on the isSelected function to determine which value is selected by default.

function buildSelect(selName,selSize,selStyle,dataSet,fldValue,fldDesc,strDefault,firstDesc)
	if not(dataSet.bof and dataSet.eof) then
		dataSet.movefirst
	end if
	strSel = "<select name='" & selName & "' size='" & selSize & "' style='" & selStyle & "'>"
		if firstDesc <> "" then
			strSel = strSel & "<option value='" & strBSDefault & "'" & isSelected(strBSDefault,strDefault) & ">" & firstDesc
		end if
		do while not dataSet.eof
			strSel = strSel & "<option value='" & dataSet(fldValue) & "'" & isSelected(dataSet(fldValue),strDefault) & ">" & dataSet(fldDesc)
			dataSet.movenext
		loop
	strSel = strSel & "</select>"
	buildSelect = strSel
end function

Permanent link to this article: https://www.wperry.net/code/buildselect/

Leave a Reply

Your email address will not be published.