Solved

Enumerating Form Field Values

Posted on 2004-04-12
6
814 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
ID: 10804221
<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
ID: 10804243
btw, here's the entire ASP objects collection,

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

Author Comment

by:ncw
ID: 10804704
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
Sleepyhead_NO earned 250 total points
ID: 10805315
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
ID: 10806467
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
ID: 10809735
"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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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