Solved

Enumerating Form Field Values

Posted on 2004-04-12
6
806 Views
Last Modified: 2008-03-10
I have a form in an asp page and I want to transfer the form values to another asp page which I can do by submitting the form to eg page2.asp. Inside page2.asp I believe I can return specific field values using:

Request.form("fieldname")

However because the field names were written dynamicly, I don't know the field names; how can I loop through the fields collection checking for certain field types.
0
Comment
Question by:ncw
  • 3
  • 2
6 Comments
 
LVL 30

Expert Comment

by:third
Comment Utility
<h3> Form Collection </h3>
<%
For Each Item in Request.Form
  For iCount = 1 to Request.Form(Item).Count
    Response.Write Item & " = " & Request.Form(Item)(iCount) & "<br>"
  Next
Next

for each qryItem in Request.Form
 strMsgInfo = strMsgInfo &  qryItem & " :: " & request.Form(qryItem) + vbNewLine + vbNewLine
next

Response.Write strMsgInfo
%>
0
 
LVL 30

Expert Comment

by:third
Comment Utility
btw, here's the entire ASP objects collection,

http://www.4guysfromrolla.com/webtech/021099-1.shtml
0
 
LVL 1

Author Comment

by:ncw
Comment Utility
From this I seem to be able to return the name and value of all input fields; how can I return the id value? The reason is that the form has items for selection by checkboxes and the checkboxes take the name of the associated item with the checkbox value set to the item value, but there are other hidden text fields too which I know the names of? I just want to enumerate the fields of type checkbox or fields with an id of eg "chk".

The object collection debug page was good, thanks.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Accepted Solution

by:
Sleepyhead_NO earned 250 total points
Comment Utility
you can't return the id value - it is for client side scripting only. When the form is posted only the request name and value is posted to the action page.

If you only want to list thos form elements with name = "chk" then do this:

dim form_item
for each form_item in request.form
     if form_item = "chk" Then
           response.write form_item & " = " & request.form(form_item).value & "<br>" & vbNewLine
     end if
next
0
 
LVL 1

Author Comment

by:ncw
Comment Utility
In my page I use asp to write a list of options which have different descriptions and different prices, and against each I have a checkbox. What  I was hoping was to set the name of each checkbox to the description of the option and set the value to the option price and then, in the asp page the form is submitted to, enumerate the names and values of all checked checkboxes. I could do that if only the checkboxes were submitted but I am also submitting values in hidden fields.

I guess I could preceed each checkbox name with 'chk_' and then check the first 4 letters of each item name for 'chk_'. Can you see a better way?
 
0
 
LVL 30

Expert Comment

by:third
Comment Utility
"I guess I could preceed each checkbox name with 'chk_' and then check the first 4 letters of each item name for 'chk_'."

yup. this is a good idea but the better way i'm thinking is, you assign common name to each of your checkboxes and set the value of the checkbox to description+delimeter+price format (i.e. <input type="check" id="chk" name="chk" value="desc|1.00">). then on your action page, you can loop through the chk form array and split each value by the delimeter to get the description and price.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now