Solved

Enumerating Form Field Values

Posted on 2004-04-12
6
811 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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