Checkbox Set To OFF Not In Request.Form

D

Dan

When using checkboxes on a form, if you uncheck them, the unchecked
name/value pair in the Request.Form collection doesn't show up. It only
shows when the checkbox is set to ON.

Is this correct? What's the workaround if it is?
 
R

Ray at

Dan said:
When using checkboxes on a form, if you uncheck them, the unchecked
name/value pair in the Request.Form collection doesn't show up. It only
shows when the checkbox is set to ON.

Is this correct?

Yes it is.
What's the workaround if it is?
That depends on what you're trying to do. What are you trying to do?

Ray at work
 
A

Aaron Bertrand - MVP

Is this correct?

Yep.
What's the workaround if it is?

Well, that depends. If you are trying to store state in a database, rather
than trying to figure out what checkboxes WEREN'T checked, is I clear the
data and then start fresh with only the options that were checked. This
logic is much easier, and works well with checkboxes that are generated
dynamically...

Other things you can do:

<input type=hidden name=possible value='a, b, c'>
<input type=checkbox name=actual value='a'> A
<input type=checkbox name=actual value='b'> B
<input type=checkbox name=actual value='c'> C

Then on the receiving page, you can compare the strings. If they differ,
you can use split to determine which elements are still in possible that
aren't in actual (previously checked but no longer checked).

A
 
A

Aaron Bertrand - MVP

Then on the receiving page, you can compare the strings. If they differ,
you can use split to determine which elements are still in possible that
aren't in actual (previously checked but no longer checked).

Oh and you can also determine which ones were previously unchecked and now
are checked, e.g.

<input type=hidden name=possible value='a, b, c'>
<input type=hidden name=previous value='a, b'>
<input type=checkbox name=actual value='a' CHECKED> A
<input type=checkbox name=actual value='b' CHECKED> B
<input type=checkbox name=actual value='c'> C

Now, you can compare actual to possible (to determine those that are
unchecked) and you can also compare actual to previous (to determine both
those that were previously checked and have been turned off, and those that
were previously unchecked and have been turned on).
 
D

Dan

I'm trying to implement a SQL Server 2000 'edit record' page that has BIT
fields (boolean value).
 
R

Ray at

Uh, fine. :] But, what are you trying to do that requires that you know if
a checkbox has been unchecked? What Aaron suggested will typically work for
most things. The synapse between your explanation below and the checkbox
query is a bit too large.

Ray at work
 
P

Phillip Windell

Why not just this:

MyVar = Request.Form("MyCheckBox")
If MyVar <> "ON" Then MyVar = "OFF"

'Now the MyVar will either be "ON" or it will be "OFF"


--

Phillip Windell [CCNA, MVP, MCP]
(e-mail address removed)
WAND-TV (ABC Affiliate)
www.wandtv.com

Ray at said:
Uh, fine. :] But, what are you trying to do that requires that you know if
a checkbox has been unchecked? What Aaron suggested will typically work for
most things. The synapse between your explanation below and the checkbox
query is a bit too large.

Ray at work

Dan said:
I'm trying to implement a SQL Server 2000 'edit record' page that has BIT
fields (boolean value).


"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
up. It
only
 
D

Dan

I have a canned routine that reads the Request.Form collection and prepares
the INSERT or UPDATE statement. If a checkbox is initially checked, and is
then unchecked, that field name won't make it into the Request.Form
collection for the auto-generation of the SQL UPDATE statement without a
changing my canned routine that's heretofore been working fine (without the
use of checkboxes on the form). So, I'll modify my routine to detect this
special handling.
 
D

Dan Sikorsky

Your solution will handle a particular case, but I need to detect state info
(see my response to Aaron Bertrand).

--
Thank you,

Dan Sikorsky MSCS, BSCE, BAB


Phillip Windell said:
Why not just this:

MyVar = Request.Form("MyCheckBox")
If MyVar <> "ON" Then MyVar = "OFF"

'Now the MyVar will either be "ON" or it will be "OFF"


--

Phillip Windell [CCNA, MVP, MCP]
(e-mail address removed)
WAND-TV (ABC Affiliate)
www.wandtv.com

Ray at said:
Uh, fine. :] But, what are you trying to do that requires that you know if
a checkbox has been unchecked? What Aaron suggested will typically work for
most things. The synapse between your explanation below and the checkbox
query is a bit too large.

Ray at work

Dan said:
I'm trying to implement a SQL Server 2000 'edit record' page that has BIT
fields (boolean value).


"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message

When using checkboxes on a form, if you uncheck them, the unchecked
name/value pair in the Request.Form collection doesn't show
up. It
only
shows when the checkbox is set to ON.

Is this correct?

Yes it is.

What's the workaround if it is?
That depends on what you're trying to do. What are you trying to do?

Ray at work
 
D

Dan Sikorsky

(see my response to Aaron Bertrand)

--
Thank you,

Dan Sikorsky MSCS, BSCE, BAB


Ray at said:
Uh, fine. :] But, what are you trying to do that requires that you know if
a checkbox has been unchecked? What Aaron suggested will typically work for
most things. The synapse between your explanation below and the checkbox
query is a bit too large.

Ray at work

Dan said:
I'm trying to implement a SQL Server 2000 'edit record' page that has BIT
fields (boolean value).
 
P

Phillip Windell

I looked and I don't see the problem. I don't see "detecting state"
having any bearing on it. Yes you routine that gathers the values
would have to change, but that is kinda a "given".

--

Phillip Windell [CCNA, MVP, MCP]
(e-mail address removed)
WAND-TV (ABC Affiliate)
www.wandtv.com
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top