Microsoft Knowledge Base Email Alertz

(163499) - This article provides an example of how to simulate a dynamically growing form using Active Server Pages. This example allows you to enter items one at a time, and add them to a list. Once the list has been created, it can be submitted as a whole.

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 163499 - Last Review: May 2, 2006 - Revision: 4.1

How To Use Active Server Pages to Create a Dynamically Growing Form

This article was previously published under Q163499

On This Page

SUMMARY

This article provides an example of how to simulate a dynamically growing form using Active Server Pages. This example allows you to enter items one at a time, and add them to a list. Once the list has been created, it can be submitted as a whole.

MORE INFORMATION

In the following example, a basic form is drawn with one text box. You can enter information in that text box, and click Add Item to List. This button submits the form to the same file. As each item is entered, it is added to the form as a new text box with the name ITEMS. Ultimately when the whole list is submitted, there are several items in the list that can be looped through as a collection of ITEMS.

To test this technique, save the text below to a file named Dynaform.asp. Be sure that this file is located in an IIS Virtual Root.

File: DYNAFORM.ASP

   <%@ language = vbscript%>
   <% Response.Expires = 0 %>
   <HTML>
   <HEAD>
   <TITLE>Dynamically Growing Form</TITLE>
   </HEAD>
   <BODY>
   <%
   If Request("Action") = "Submit the List" Then

     ' Show what was entered.
     Response.Write "<B>Here are the Items submitted:</B><BR>"
       nItems = Request.Form("Items").Count
       For i = 1 To nItems
         ' Show submitted Items
         Response.Write Request.Form("Items")(i) & "<BR>"
         Next
         Response.Write Request("Item") & "<BR>"

   Else

     ' Create the form from all items. %>
     <FORM Action=dynaform.asp Method=Post>
     <B>Items:</B><BR>
     <%
     nItems = Request.Form("Items").Count
     For i = 1 To nItems
       ' Show previously submitted Items
       Response.Write "<INPUT Type=Text Name=Items Value=""" & _
         Trim(Request.Form("Items")(i)) & """><BR>"
     Next

     If Request.Form("Item") <> "" Then
       ' paint a new input box, and store the old Item in Items collection
       Response.Write "<INPUT Type=Text Name=Items Value=""" & _
         Trim(Request.Form("Item")) & """><BR>"

       Response.Write "<P>Please enter an Item,<BR>"
       Response.Write "and submit them one at a time<BR>"
       Response.Write "by pressing the Add Item button.<BR>"
       Response.Write "<INPUT Type=Text Size=50 Name=Item Value="""""">"
     Else
       ' No Item was submitted, don't show an error
       Response.Write "<P>Please enter an Item,<BR>"
       Response.Write "and submit them one at a time<BR>"
       Response.Write "by pressing the Add Item button.<BR>"
       Response.Write "<INPUT Type=Text Size=40 Name=Item Value="""""">
       <BR>"
     End If

   %>

     <P>
     <INPUT Type="Submit" Name="Action" Value="Add Item to List">
     <INPUT Type="Submit" Name="Action" Value="Submit the List">
     <BR>

   <% End If %>

   </FORM>
   </BODY>
   </HTML>
				

REFERENCES

For the latest Knowledge Base articles and other support information on Visual InterDev and Active Server Pages, see the following page on the Microsoft Technical Support site:
http://support.microsoft.com/search/default.aspx?qu=vinterdev (http://support.microsoft.com/search/default.aspx?qu=vinterdev)

APPLIES TO
  • Microsoft Active Server Pages 4.0
  • Microsoft Internet Information Server 4.0
  • Microsoft Internet Information Services 5.0
Keywords: 
kbcodesnippet kbhowto KB163499
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Anonymous User Report As Irrelevant  
Written: 3/22/2004 6:08 AM
Please note that on order for this script to work, the <BR>" just above the End If statement needs to be moved up the the end of the previous line. Otherwise you might be getting an ASP error.
     Else
       ' No Item was submitted, don't show an error
       Response.Write "<P>Please enter an Item,<BR>"
       Response.Write "and submit them one at a time<BR>"
       Response.Write "by pressing the Add Item button.<BR>"
       Response.Write "<INPUT Type=Text Size=40 Name=Item Value="""""">
       <BR>"
     End If