Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Request.Form problem

Status
Not open for further replies.

scribbler

MIS
Feb 4, 2002
206
GB
I have a variable number of checkboxes on my form which I submit to a formhandler. I used the formhandler ok but I need to add a hidden field to the form which I've done but I'm unsure how I read this hidden field out on my form handler as it reads ok but is repeated in the for/next loop and I wanted to read this in seperately to be displayed eslewhere on my formhandler page.

My formhandler has the following code;

Dim checkbox(100,2)
response.Write "Hidden Field=" & Request.Form(1) & "<br><br><br>"
For Each x in Request.Form
i = i + 1
checkbox(i,0)=x
checkbox(i,1)=Request.Form(x) ' This contains the actual price of the option
response.Write ("Description Of Selected Option=") & checkbox(i,0) & ("<br>")' Description Of Selected Option/Checkbox
response.Write ("Price Of Selected Option=") & checkbox(i,1) & "<br><br>"
Next


If it helps my original problem started out as thread216-1011007
 
You can use an if... then... statement to test for the Hidden field, as long as the value does not match any of your checkbox values.

Code:
Dim checkbox(100,2)
response.Write "Hidden Field=" & Request.Form(1) & "<br><br><br>"
For Each x in Request.Form
  i = i + 1 
  checkbox(i,0)=x

  if request.form(1)<>request.form(x) then
    checkbox(i,1)=Request.Form(x) ' This contains the actual price of the option
    
    response.Write    ("Description Of Selected Option=") & checkbox(i,0)  & ("<br>")' Description Of Selected Option/Checkbox

    response.Write    ("Price Of Selected Option=") & checkbox(i,1) & "<br><br>" 
  end if
Next

I hope this helps.
 
psappenfield

Thanks for opening my eyes. It was late at night by the time I got to this point and now it's pretty obvious what I needed to do to trap the first item.

Sometimes code needs a fresh pair of eyes as I get word blindness... or at least thats my excuse for being dumb..
 
psappenfield

I thought by using your suggested code I had this problem sorted and all worked well until further testing. I used 4 hidden fields followed by a variing number of chekcbox/options but what happened was that the results were unpredicable in that the order in which hidden fields came up was mixed between the variable checkbox/options fields. This got worse when I noticed that if I checked option No. 11 each time it threw the results haywire. I searched the net and ammended the code using request.form.count which gave me the results in correct order i.e. hidden fields first (1-4) followed by values of options but I cannot get the checkbox descriptions to appear. Can you advise me further ?

Session.LCID = 2057
Dim formvalues(100,2)
Dim x
response.Write "SelectedOptionsValue=" & Request.Form(1) & "<br>"
response.Write "PriceWithOptions=" & Request.Form(2) & "<br>"
response.Write "BasicPrice =" & Request.Form(3) & "<br>"
response.Write "selected_description=" & Request.Form(4) & "<br><br>"


For x = 5 to Request.Form.count '5 being the 1st option after my hidden fields
i = i + 1
formvalues(i,0)= x 'formvalues(i,0)=x will be the option name eg 'Checkbox12'
formvalues(i,1)=Request.Form(x) 'formvalues(i,1)=Request.Form(x) will be the value eg '5.5'
response.Write ("formvalues(i,0)=") & formvalues(i,0) & ("<BR>")
response.Write ("formvalues(i,1)=") & formvalues(i,1) & ("<BR><BR>")
Next
i=0


'incidentally ... how do you get the actual code to display as you do on the Tek-Tips forum ?
 
I actually had to figure this out a couple of weeks ago, and I was searching everywhere for the answer. I want to make sure I understand you correctly -

You are trying to get the name of the field and value, and you want it in the order that the form is laid out.

If so, you must use a combination of a "for next" loop and a "for each" loop. I created a string to keep track of which variables were already "used" in the loops.

Please keep in mind that I am working from memory here... The actual code is at work, so there might be a few kinks in the code.

Code:
for i=1 to request.form.count
  for each item in request.form
    if InStr(strUsedItems,item)<0 and request.form(item)=request.form(i) then 
      select case item
        case <<List of Other Fields>>
          'do special formatting
        case <<checkboxes or you can use else>>
          response.write item&": "&request.form(item)&"<br>"
      end select
      strUsedItems=strUsedItems&","&item
    end if
  next
next

One other thing that I learned during my search is that not all browsers order the form elements in the same way, so you may need to test for this if that is a concern for you.

For the code tags, you use:
[ code ]Insert your code here[ / code ]
without the extra spaces. There is a note on this at the bottom of the Preview Post page.

Hope this helps [bigsmile]
 
psappenfield

thanks for getting back to me. I only just read this at 3:50pm so I'll check it out and let you know how I get on. I'm stuggling here as all the books I ordered on asp & flash havent arrived and I spend more time search web than writing code that I struggle to understand at times.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top