msnews.microsoft.com wrote:[color=blue]
>
> ...If Request.form("CheckBoxName") then ....
>
> However, in the page B, the same code raises a "type mismatch"
> error, and it has to be modified as follows for the codes to run :
>
> If Request.form("CheckBoxName") <> "" then ....[/color]
All of the other replies seem to be treating Request.form("CheckBoxName") as
if it is a string, when it is, in fact, an object with properties. I suggest
that you simply examine the appropriate property rather than depend upon
implicit conversion of the default property of an object that may or may not
exist.
In other words, this does exactly what you want; as a bonus, its language
encapsulates your logic much more closely than string comparison (I'll show
why this is important in a moment):
If Request.Form("CheckBoxName").Count > 0 Then ...
According to the HTML spec, a checked (or "on") checkbox is a successful
control, and will generate a name-value pair:
http://www.w3.org/TR/html401/interac...ssful-controls
So what happens if you do something silly like this**?
<INPUT NAME="CheckBoxName" TYPE="checkbox" VALUE="">
If you code it this way and the user checks the control, he has selected it,
and any server-side decisions based on that control state should reflect the
user's choice. But only one of these treats it correctly:
If Request.Form("CheckBoxName") Then ...
If Request.Form("CheckBoxName") <> "" Then ...
If Request.Form("CheckBoxName").Item Then ...
If Request.Form("CheckBoxName").Item <> "" Then ...
If Request.Form("CheckBoxName").Count > 0 Then ...
Care to guess which one?
**Since it does not have a current value, the W3C says the browser is not
*required* to treat it as a successful control. By my observation, some do
(IE6 and Mozilla), while others do not (Opera).
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.