Advertisement
5_2007-2008 Files/ File Controls/ Input/ Output #176900

Select List Thingy

*UPDATED 10-23-00* Now with more options, including multiple select, size, and default selected option. Quickly and easily creates select list combo boxes from a database for your web forms. Uses .GetString rather than recordset looping.

AI

KI-Zusammenfassung: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Quellcode
original-source
<%
'***************************************
'* Function Name: buildCombo
'* Syntax : myVar = buildCombo
'* Parameters : 
'*		rsRecordset - Name of an OPEN 
'*					recordset with 2 fields
'*		strComboName - String with the name
'*					you want to appear in 
'*					<select name='' id=''>
'*		strFirstOption - String with what 
'*					the first option should 
'*					be, ex: 
'*			<option value="0">N/A</option>
'*		blnMultiple - Boolean for mult.
'*					option or not...should 
'*					be FALSE unless you set
'*					strSize
'*		strSize - String for size (rows)
'*					to display
'*		strSelected - String of the 
'*					selected value, if you 
'*					want an option 
'*					autoselected
'*
'* Description : Quickly creates a drop-
'*		down list without looping a 
'*		recordset, and minimal 
'*		concatination
'*
'* Example :
'*		myCombo = buildCombo(rsTmp,
'*		"usr_id","<option value='0'>N/A
'*		</option>",True,"5","0")
'*
'* Result :	Produces a 5 row multiple 
'*		select list called usr_id with 
'*		the first display as N/A and 
'*		selected as default
'***************************************
function buildCombo(byref rsRecordset,strComboName,strFirstOption,blnMultiple,strSize,strSelected)
	Dim strCombo
	Dim strLstSize
	Dim i
	If Len(Trim(strSize)) > 0 Then
		strLstSize = " size=""" & strSize & """"
	Else
		strLstSize = ""
	End If
	If blnMultiple Then
		strCombo = "<select id=""" & strComboName & """ name=""" & strComboName & """ multiple" & strLstSize & ">"
	Else
		strCombo = "<select id=""" & strComboName & """ name=""" & strComboName & """" & strLstSize & ">"
	End If
	If strFirstOption <> "" Then
		strCombo = strCombo & strFirstOption & vbCrLf
	End If
	With rsRecordset
		If Not (.EOF And .BOF) Then
			If Not .BOF Then
				'Just making sure in case you were previously doing something else
				.MoveFirst
			End If
			strCombo = strCombo & "<option value='" & .GetString(,,"'>","</option>" & vbCrLf & vbTab & "<option value='","" )
		Else
			'No records returned
			buildCombo = "<select><option>No Records Returned</option></select>"
			exit function
		End If
	End With
	strCombo = strCombo & "</select>"
	i = InStrRev(strCombo,"<option value='</select>")
	If i > 0 Then
		'Remove the extra <option value=' from the end of the string
		'It will work fine with it in there, but we like to be tidy don't we?
		strCombo = Replace(strCombo,"<option value='</select>","</select>")
	End If
	If Len(Trim(strSelected)) > 0 Then
		strCombo = Replace(strCombo,"<option value='" & strSelected & "'>","<option value='" & strSelected & "' selected>",1,1)
	End If
	buildCombo = strCombo
end function
%>
Originalkommentare (3)
Wiederhergestellt von der Wayback Machine