Small API tag helper for SELECT and OPTION tags by Salim N.Attached is a small API that is a great helper for ASP programmers. It's a SELECT tag helper and contains advanced features such as Multiple OPTION caption for the Same OPTION value. It's not the most advance script routine in the world but it sure is helpful and a clean way to program. Here is the code <% '------------------------------------------------------------------------------ 'This is a generic <SELECT> Element Helper function '------------------------------------------------------------------------------ 'Written By: Salim Naim 20/3/2000 'Note: I'm more than happy to fix any Bugs or answer any questions regarding the 'sample,i can be reached at snaim@zfp.com or salimn@yahoo.com
'------------------------------------------------------------------------------ 'Example Use 1: 'Simple basic usage 'Call OutputSelect("country","COUNTRYNAME","COUNTRYNUM","","SELECT * FROM COUNTRIES","DSN=..") '------------------------------------------------------------------------------ 'Example Use 2: 'This will output multiple option captions for the <OPTION> selection 'Call OutputSelect("USERS","FIRSTNAME,LASTNAMSE","USERNUM","","SELECT * FROM USERS","DSN=..") 'Note: the field captions, must be delimited by a coma , '------------------------------------------------------------------------------ '###### USE THE szSelected PARAMETER TO SET A DEFAULT SELECTED OPTION ####### '------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------- ' Function: OutputSelect ' Description: This Functin is a Helper function that outputs ' a <select>..</select> based on your query. '--------------------------------------------------------------------------------------- ' Parameters: name - This is the HTML ATTRIBUTE for NAME ' fiedlcaption - These are the Fieldsnames from the Database that ' you want to output in the <option>. ' {Note: can contain multiple, use [,] as a delimeter.) ' fieldvalue - This is the Database fieldname that you want to be as ' the VALUE ATTRIBUTE. ' szSelected - The SELECTED VALUE from the List. ' szQry - The SQL Statment to populate the LIST from ' szDSN - The Data Source Name for the RecordSet '--------------------------------------------------------------------------------------- Sub OutputSelect(name,fieldcaption,fieldvalue,szSelected,szQry,szDSN) Dim objRS Dim aCaptions,szCaption Dim i
'first split all the captions into an array. aCaptions = split(fieldcaption,",")
'create our recordset. Set objRS = Server.CreateObject("ADODB.RecordSet") if Not IsObject(objRS) then Response.Write "Out of Resources" Response.End End if
'execute the Query objRS.Open szQry,szDSN if Not objRS.EOF then%> <%'start the list, output the NAME%> <select name="<%=name%>"> <option value=""></option> <%While Not objRS.EOF%> <%'only output the values that are not selected if Not szSelected = objRS(fieldvalue) then%> <%'in the case that the value is empty output the caption as the value if Len(Trim(fieldvalue)) > 0 then%> <option value="<%=objRS(fieldvalue)%>"> <%'Output every caption that is in the array for each szCaption in aCaptions%> <%if Len(Trim(szCaption)) > 0 then%> <%=objRS(szCaption)%> <%end if%> <%next%> </option> <%else%> <option value="<%=objRS(fieldcaption)%>"> <%for each szCaption in aCaptions%> <%if Len(Trim(szCaption)) > 0 then%> <%=objRS(szCaption)%> <%end if%> <%next%> </option> <%end if%> <%'the selecte values else%> <option value="<%=objRS(fieldvalue)%>" selected> <%for each szCaption in aCaptions%> <%if Len(Trim(szCaption)) > 0 then%> <%=objRS(szCaption)%> <%end if%> <%next%> </option> <%end if%> <%objRS.MoveNext Wend%> </select> <%End if 'close up everything Call objRS.Close() 'free resources. Set objRS = Nothing End Sub%> |
|
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP Code Articles More By aspfree developerWorks - FREE Tools! | Join this Rational Talks to You teleconference, featuring Paul Boustany and Mark Krasovich, to speak to the experts about becoming a Rational ClearCase power user. Get a chance to ask your questions and learn tips and tricks for using Rational ClearCase in Agile development FREE! Go There Now!
| | | | Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base. FREE! Go There Now!
| | | | You probably have thousands of lines of COBOL code loaded with business intelligence and being used to run your business, along with an army of developers maintaining these applications. Learn how to prepare your applications and developers so you can keep that competitive edge and move to a service-oriented architecture with the IBM Rational Enterprise Modernization solutions. Replay is available for 9 months. FREE! Go There Now!
| | | | Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects. FREE! Go There Now!
| | | | This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product. FREE! Go There Now!
| | | | Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository. FREE! Go There Now!
| | | | XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats. FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components. FREE! Go There Now!
| | | | Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications. FREE! Go There Now!
| | | | With IBM Rational Systems Development Solution, you can deliver products faster with higher quality. Within this kit, Read the “Model Driven Systems Development” white paper to see how to improve product quality and communication. Then check out the rest of the e-Kit to learn more about important topics that can affect the success of any software project through customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems. From start to finish, at every stage in your projects, Rational Systems Development Solution can help your company reach its full potential. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |