Looping through form objects - syntax question

S

sean

HI There,

I am trying to loop through a form collection, each of the form textfields
has a different index number but the same name. What's the easiest way for
me to get the values from each one? I have tried the following but it's not
working at all,could somone help me out with the syntax please?


Sean - thanks in advance foryour answer.

Request("productid" & i).count


<INPUT type='hidden' NAME='productid1' ID='productid1'
value="3TTT:C4XXN23222">
<INPUT type='hidden' NAME='productid2' ID='productid2'
value="3TTT:C4XXN232">
<INPUT type='hidden' NAME='productid3' ID='productid3' value="3TTT:C4XXN23">

i=0

for i = 1 to Request("productid").count
strOption = Request("productid")(i)
next
 
U

Utada P.W. SIU

<INPUT type='hidden' NAME='productid' value="1TTT:C4XXN11111">
<INPUT type='hidden' NAME='productid' value="2TTT:C4XXN22222">
<INPUT type='hidden' NAME='productid' value="3TTT:C4XXN33333">

dim product
product = split(request("productId"))
for i = lbound(product) to ubound(product)
'-- do anything you want
next
 
S

sean

HI There,

This does not work! the object name has a number with it, in your example
your telling me to look for productid. The names are all different and your
script does not cater for this.

Thanks anyway

Sean
 
A

Armando

Why are you using request and not request.form to retrieve the values from
the form fields?
 
S

sean

I was only using the script that was posted, however the fields on the form
are not called "productid" they are "productid(index name)". So the script
does not work at all.

any ideas?

Sean
 
A

Armando

<INPUT type='hidden' NAME='productid1' ID='productid1'
If these are your form fields you need to run the for/next loop and change
the name of the field in each subsequent loop, that's where your i comes
into play. So if your form fields are numbered sequentially and called
'productid(1)', 'productid(2)', and 'productid(3)' your for/next loop should
look like this:

for i = 1 to [however many fields you need to read]
strOption = request.form("productid("& i &"))
'insert code here to do something with the strOption data
next

Remember that strOption will be overwritten on each loop, so you'd want to
put some other code in there where I indicated to do something with the data
before it gets overwritten in the next loop. Hope this helps. Cheers.

Armando
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top