Not all controls in a form always get returned.
This can cause problems if you're not expecting it.
Request("TermName")(1)
will cause an invalid procedure call (VB error #5)
if no term in the request has that name.
This happens when:
a CheckBox is not checked
no Radio button in a group is selected
no Option in a list box is selected.
To avoid this problem, use the GetRequest function to do this.
GetRequest("InputName")
HTML Forms Tip - How to group Radio buttons
As you may know from VB, Radio buttons (Option buttons) go in groups.
To group HTML Radio buttons, give them all the same name.
Only one Radio button in a group can be selected at a time.
The value of the selected Radio button is the one that gets sent back in the request.
Therefore, all the Radio buttons in a group should have different names.
The default value of a Radio button is on.
Multi-Select
The Select tag has the MULTIPLE attribute
that lets the user select multiple options from a list box.
All options selected get sent in the request as separate terms
all with the same name.
This presents a particular problem.
Each name in the request is not associated with just one value.
As a result, each item in the Request collection is actually
a collection of values as depicted in this figure.
An index is used to pick values from the sub collection.
You can get the second selected option in a list box named Product like this.
Request("Product")(2)
To find the number of products selected use:
Request("Product").Count
You could show all the selected values like this:
For Each Prod In Request("Product")
SendLn Prod, "<BR>"
Next
Even if a name does get sent with just one value,
it still gets put into a collection of Values with just one item.
(That's why the (1) is required, in case you were wondering.)
A Multi-Select list box is not the only time the index is useful.
Two inputs in a form can have the same name and they will still get sent.
This is similar to a Control Array in VB.
This can be useful for forms with a lot of the same kind of inputs.
You could send visitors an entire table of fields and records all on one page.
Each line would have the same set of fields and field names.
Names Collection
Let's say you want to do something special with all the terms
that have a name beginning with Top.
But you want to add inputs to the HTML form
without having to make code changes.
To do that, you need a way go through all the term names.
Although you use names in the Request collection,
you cannot get those names back out.
Instead, use the Names collection.
Here are two examples, one using an index and one using For Each.
For i = 1 To Names.Count
If Left(Names(i), 3) = "Top" Then
SendLn Names(i), "is", Request(i)(1), " "
End If
Next i
For Each Name In Names
If Left(Name, 3) = "Top" Then
SendLn Name, "is", Request(Name)(1), " "
End If
Next