WelcomeServicesPortfolioKnowledge BaseContact Us
27 Seconds, Inc.


Knowledge base View Article

need hosting?

Need hosting? We use and love our host - CrystalTech.com!
Need hosting? We use and love our host - CrystalTech.com!

Text Disguise - CAPTCHA-image/Human Interactive Proof web services

National Holiday Dates and Bank Holiday Dates - web site that provides the dates of national and bank holidays for the United States, United Kingdom, Ireland and Scotland

Holiday Web Service - web services for programmers to provide the dates of national and bank holidays in their applications for the United States, United Kingdom, Ireland and Scotland

Our Family Heart - web site to help families communicate no matter where they are

What?! You haven't heard about the greatest remote controlled flyer to come out in years?! Checkout the FlyTech DragonFly now!

Add Option

Summary: Easily add an option to a select box with this function.
 
Keywords: LIST BOX
LISTBOX
OPTION
SELECT
Applicable Software: Active Server Pages (ASP)
 
Body:

A common task, in ASP is to add options to a SELECT list. And, just as common, you want to have a particular option preselected.

To add the options, and preselect a particular one, you can use the function:

Function AddOption(DisplayValue, BackendValue, CurrentSelection)
Dim m_sOut
	m_sOut = "<option value=""" & BackendValue & """ "
	If LCase(Trim(BackendValue & "")) = LCase(Trim(CurrentSelection & "")) Then
		m_sOut = m_sOut & "SELECTED "
	End If
	m_sOut = m_sOut & ">" & DisplayValue & "</option>"

	AddOption = m_sOut

End Function

<%
Dim sPreselect
    sPreselect = "P"
%>
<SELECT Name="selectExample">
<%=AddOption("Apples", "A", sPreselect) %>
<%=AddOption("Oranges", "O", sPreselect) %>
<%=AddOption("Pears", "P", sPreselect) %>
</SELECT>

 
Author: Douglas L. Setzer, II, http://www.27seconds.com
Posted On: 3/5/2002 10:37:24 AM

Rate this article: Average: 7
n/a12345678910
Comments?

Article Search   |   All Articles

 

 
©2002 27 Seconds, Inc. All Rights Reserved.