asp

  • Thread starter msnews.microsoft.com
  • Start date
M

msnews.microsoft.com

Hello,

I have two asp pages (A and B) to be run on the same server and from the
same client.


1. In the page A, a checkbox value (checked or not checked) can be
recognised in the following code :

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 ....


2. In the page A, even if a recordset does not exist as a result of a
query, it is ignored and the codes can run without error. However, in the
page B, non-existing recordsets raise an "item cannot be found" error.

I tried to find out the differences of these two asp pages, but I am so far
not able to. Does anybody has an idea ?

Thank you very much,

Kiyomi
 
E

Evertjan.

msnews.microsoft.com wrote on 09 jun 2004 in
microsoft.public.inetserver.asp.general:
I have two asp pages (A and B) to be run on the same server and from
the same client.


1. In the page A, a checkbox value (checked or not checked) can be
recognised in the following code :

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 ....

If Request.form("CheckBoxName") then ....

Request.form() always returns a string!

if the string content of CheckBoxName is not litterally true, false or an
empty string an error will be shown.

Change it to:

If lcase(Request.form("CheckBoxName"))="true" then ....

or even better: control your form input.
 
C

CJM

Evertjan. said:
If Request.form("CheckBoxName") then ....

Request.form() always returns a string!

if the string content of CheckBoxName is not litterally true, false or an
empty string an error will be shown.

Change it to:

If lcase(Request.form("CheckBoxName"))="true" then ....

or even better: control your form input.

I think that this is correct solution:

If Request.form("CheckBoxName")="on" then ....

Chris
 
D

Dave Anderson

msnews.microsoft.com said:
...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 ....

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/interact/forms.html#successful-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.
 

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
474,156
Messages
2,570,878
Members
47,404
Latest member
PerryRutt

Latest Threads

Top