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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

for each Item in Request.Form---Sort Order Question 4

Status
Not open for further replies.

puitar

Programmer
Apr 8, 2001
64
AU
Greets,

I have a form with many tick boxes. Example names for these are... tckERD023_USQ_MOD1_0023, tckERT023_USQ_MWD1_0223....

When I use..

for each Item in Request.Form
[boring code goes here]
next

the order the tick boxes are processed looks random. I want to look at each tick box from 1st to last like they are ordered on the form.

How do I control this? Can I control the order?

Please help....My code is below. I'm creating a text file from the form details.



for each Item in Request.Form
if request.Form(Item) = "Yes" then
Pos1 = instr(item, "_") '1st Underscore
pos2 = pos1 + instr(right(item,len(item)-pos1),"_") ' 2nd underscore
pos3 = len(item)-5 ' 3rd underscore

CourseCode = mid(item,4,pos1-4)
CourseName = mid(item,pos1+1,pos2-pos1-1)
ModuleName = mid(item,pos2+1,pos3-pos2)
tPrice = cint(right(item,4))
tTotal=tTotal+tPrice



' write course name
if tTemp<>CourseName then
tApply = tApply & vbcrlf & CourseName & vbcrlf
end if
tApply = tApply & &quot; &quot; & CourseCode & &quot; - &quot; & ModuleName & &quot; $&quot; & tprice & vbcrlf

tTemp= CourseName

end if
next
 

You need to give each form checkbox a unique name - an index number would work best. You can assign the indexes based on the order you want it processed.

e.g.,

<INPUT TYPE=checkbox name=&quot;myChk_1&quot;>
<INPUT TYPE=checkbox name=&quot;myChk_2&quot;>
<INPUT TYPE=checkbox name=&quot;myChk_3&quot;>

Then when you process the form, refer to the checkboxes using the index like:

For i=1 to 3
myRetrievedValue = Request.Form(&quot;myChk&quot; & i)
...
Next

I hope this answers your question.

Multiplex
 
mmmm.... I am trying to avoid renaming all of the tick-boxes. There are about 70 of them each with unique names.

 
I've used arrays before to simplify processing like this:
Code:
Dim chkBxs
Dim ctr
Dim IsChecked

' Add the elements in whatever order you choose.
' Remove NULL if you want a zero-based array.
chkBxs = Array(NULL,chk1,chk6,chk3,chk9,chk4,etc..)

For ctr = 1 To UBound(chkBxs)
  IsChecked = chkBxs(ctr)
  ' handle here
Next ctr

I set the first element in the array to null so I don't have to use a zero-based index. With this technique you can decide what order to process the elements in (without renaming them), and if you decide to add or subtract elements later it doesn't affect the rest of the code since it processes elements 1 to UBound().


VBSlammer
redinvader3walking.gif
 
Tick boxes are nasty, the reason your getting random results is ASP appears to &quot;skip&quot; sending tick boxes that are not &quot;ticked&quot;.
 
The other reason you are getting random ordering is because the form collection is stored in a hash table, which means the more elements you have, the less chance that they will be stored in the same order they were placed on the page.
My question is why do you have 70 checkboxes with differant names. A checkbox with a unique name can only have two values, either selected or not selected. If it is not selkected than it is not passed in the form collection.

I would prefer setting the value = to what you are now using as the name and name them all the same. This way the checked checkboxes would be passed to the second page as a comma delimited array of values. You could then for each item in Request.Form(&quot;chkBoxName&quot;) to evaluate the value strings exactly as you are attempting to evaluate the names above.

This will also retain the value of the checked boxes in relation to the order of all of the checkboxes from the previous page because they are passed as a single string that was generated client side in the order of the checkboxes.

-Tarwn
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top