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! | <a href="http://zeus.developershed.com/shonuff.php?blackbird=3853&zoneid=442&source=&dest=http%3A%2F%2Fwww.ibm.com%2Fdeveloperworks%2Fspaces%2Fjazz%3FS_TACT%3D105AGY31%26S_CMP%3DDEVSHED&ismap="><img src="http://images.devshed.com/corp/img/news/jazz01.gif" alt="developerWorks Jazz space" align="left"></a>You've heard the buzz about Jazz... want to know more about it from a developer's perspective? Check out the Jazz space on developerWorks. This space is an up-to-date resource for developers, including technical information about Jazz and products built on Jazz, like Rational Team Concert Express. The Jazz space includes content from a wide variety of sources, including links, feeds, and comments from experts. FREE! Go There Now!
| | | | Hear how IBM Rational Project and Portfolio Management integrated solutions help teams put the right tools and processes in place to maximize the effectiveness and efficiency of project teams and ensure that the business vision is being executed correctly. Learn how to automate and integrate requirements prioritization, top-down project planning, communications and controls, and methodology deployment to keep your scope, costs, and schedules under control. Tackle with an end-to-end approach the management of scope and scope changes, usage of methodology to control and empower project teams, and optimization of resources to align activity costs with the overall project plan. FREE! Go There Now!
| | | | CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP. FREE! Go There Now!
| | | | WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
| | | | Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications. 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!
| | | | Get a free trial download of the latest version of IBM Rational Functional Tester V7.0.1. Rational Functional Tester is an automated functional and regression testing solution for QA teams concerned with the quality of their Java, Microsoft Visual Studio .NET, and Web-based applications. FREE! Go There Now!
| | | | Visit IBM developerWorks to try the IBM SOA Sandbox for connectivity. The SOA Sandbox for connectivity provides a trial environment with the tooling and components to help you explore how to effectively connect your infrastructure and integrate all of the people, processes and information in your company. Use the hosted sandbox to explore SOA techniques that streamline connecting existing IT assets together, as well as learn how to connect them to new business logic. FREE! Go There Now!
| | | | Visit IBM developerWorks to try the IBM SOA Sandbox for people. The SOA Sandbox for people provides a trial environment with the necessary tooling and components required to enable consistent human and process interaction and collaboration, showing how you can improve user experience and business productivity. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |