Print Page | Close Window

Multiple Similar Fields on a Form

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=11960
Printed Date: 31 March 2026 at 4:48am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Multiple Similar Fields on a Form
Posted By: Misty
Subject: Multiple Similar Fields on a Form
Date Posted: 27 September 2004 at 1:55am

I would like to develop a form that would have about 20 similar fields (ex: txtname_1, txtname_2, txtname_3,...). Then I would like to add the information to a database that would have the same EmailID. The UserID would be unique for each name. 

I don't want to have to use request.form 20 times to retrieve all of the names. I saw code that would allow you to do request.form on txtname_1 to txtname_20  with one line of code, but I cannot remember where I saw this code. Can someone please help me with this?

 




Replies:
Posted By: Phat
Date Posted: 27 September 2004 at 4:56am
Dim I

For I = 1 to 20
    rs.Fields("txtName_" & i) = Request.Form("txtname_" & I)
Next



Posted By: Misty
Date Posted: 29 September 2004 at 9:35pm

I have this part working now. But there's another problem. All of the fields might not be filled out. Only the first field is required. It will add blank information to the database with the new UserID and Email ID. I have a desire for the ASP Page to not add information to the database from the blank text boxes. How do I solve this problem?

Here's a copy of my code:

Dim I
For I = 1 to 20
Name = Request.Form("txtname_" & I)
Email = Request.Form("txtEmail_" & I)
rs2.AddNew
rs2("Name")= Name (Blank for every blank field name)
rs2("EmailAddr") = Email (Blank for every blank field name)

rs2("EmailID") = EmailNum
rs2.Update
Next



Posted By: dpyers
Date Posted: 30 September 2004 at 12:51am
Try...

Dim I
For I = 1 to 20
Name = Request.Form("txtname_" & I)
Email = Request.Form("txtEmail_" & I) 

If Trim(Name) > "" then
   rs2.AddNew 
   rs2("Name")= Name (Blank for every blank field name)
  If Trim(EmailAddr) > "" then
        rs2("EmailAddr") = Email (Blank for every blank field name)
  End If

  rs2("EmailID") = EmailNum
  rs2.Update
End If

Next



-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: Misty
Date Posted: 30 September 2004 at 7:15pm

dpyers,

Thank you! The code worked. I used this for a web application that sends group emails. I am often notified when someone has read my email that was sent from the form. I think that you helped me to figure out the code for a web application that sent out individual emails before. This is a great resource because I like to know if my friends who have Yahoo or Hotmail email accounts read my emails or not.

 




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net