ASP and Checkboxes

J

James Jones

I've never used checkboxes in ASP, well nows the time i do it.

Im creating a login script, and want the user to be able to click on "remember me"
it keep them logged in.


how would i get that in ASP. how would i make it detect wether or not the checkbox
has been selected or not?


any help greatly apprecitated.


<input type="checkbox" name="remember_me">
 
E

Evertjan.

James Jones wrote on 19 aug 2006 in
microsoft.public.inetserver.asp.general:
I've never used checkboxes in ASP, well nows the time i do it.

Im creating a login script, and want the user to be able to click on
"remember me" it keep them logged in.


how would i get that in ASP. how would i make it detect wether or not
the checkbox has been selected or not?

Classic ASP, that is where this NG is all about, does not have checkboxes,
since ASP is serverside coding [in vbscript, jscript, etc].

Checkboxes exist in clientside html <form> structures.

Only the rendered html [sometimes with clientside schript code]
is sent to the client, never the ASP code.
<input type="checkbox" name="rememberMe">

ASP can "read" submitted form values, from <form method='post'...:

request.form("rememberMe")

or, from <form method='get'...:

request.querystring("rememberMe")
------=xx_NextPart_000_0024_01C6C31D.7D053900
<!DOCxxTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>

PLEASE, never use HTML on usenet!!!
 
J

James Jones

i know this is for Classic ASP, but i want to do what i can with text boxes
also

but im not sure what the defaults values are......such as....


check_box_value = Request.Form("checkbox_name")
IF check_box_value = "blah blah" Then
do this
Else
do this
End IF



summin like that.....but im not sure what the "blah blah" is set to after
the form is sent.

I've never used checkboxes in ASP, well nows the time i do it.

Im creating a login script, and want the user to be able to click on "remember me"
it keep them logged in.


how would i get that in ASP. how would i make it detect wether or not the checkbox
has been selected or not?


any help greatly apprecitated.


<input type="checkbox" name="remember_me">
 
B

Bob Barrows [MVP]

James said:
i know this is for Classic ASP, but i want to do what i can with text
boxes
also

but im not sure what the defaults values are......such as....


check_box_value = Request.Form("checkbox_name")
IF check_box_value = "blah blah" Then
do this
Else
do this
End IF



summin like that.....but im not sure what the "blah blah" is set to
after
the form is sent.

If a checkbox is checked when the form is submitted, the name/value pair
will be sent. if it is not checked, then the name/value pair will not be
checked. So it's simply a matter of testing whether or not it was sent:

if len(Request.Form("checkbox_name") > 0 then
'th checkbox was checked
else
'it wasn't checked
end if
 
J

James Jones

ok thanks. really helps!



Bob Barrows said:
If a checkbox is checked when the form is submitted, the name/value pair
will be sent. if it is not checked, then the name/value pair will not be
checked. So it's simply a matter of testing whether or not it was sent:

if len(Request.Form("checkbox_name") > 0 then
'th checkbox was checked
else
'it wasn't checked
end if

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
 
D

Dave Anderson

James said:
I've never used checkboxes in ASP, well nows the time i do it.

Im creating a login script, and want the user to be able to
click on "remember me"
it keep them logged in.


how would i get that in ASP. how would i make it detect wether
or not the checkbox has been selected or not?

What ever happened to experimenting to find out? Submit a form with a
checkbox checked, and again without. Compare the contents of Request.Form
(if method POST) or Request.QueryString (if GET). Try it on checkboxes with
VALUE attributes set, and again without.

That simple exercise will demonstrate all there is to know about checkboxes.
Honestly, you could have known the answer to your question in less time than
it took to ask it.

Oh, and there's the standard:
http://www.w3.org/TR/html401/interact/forms.html#checkbox

Not to mention the MSDN documentation:
http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/input_checkbox.asp
 
D

Dave Anderson

Bob said:
if len(Request.Form("checkbox_name") > 0 then
'th checkbox was checked
else
'it wasn't checked
end if

Or more simply,

VBScript:
If Request.Form("checkbox_name").Count > 0...

JScript:
if (Request.Form("checkbox_name").Count) ...


The object already has a [Count] property, so why confuse the issue by
mixing in a function and a default property?
 
B

Bob Barrows [MVP]

Oops, I left off the end parenthesis:
if len(Request.Form("checkbox_name")) > 0 then
'th checkbox was checked
else
'it wasn't checked
end if

Or more simply,

VBScript:
If Request.Form("checkbox_name").Count > 0...

JScript:
if (Request.Form("checkbox_name").Count) ...


The object already has a [Count] property, so why confuse the issue by
mixing in a function and a default property?

Habit. It was the first way I learned to deal with it, and, even though I
subsequently learned about the Count property, and started using it when I
thought of it, the len function is still the first thing that pops ino my
mind.
 
D

Dave Anderson

Bob said:
Habit. It was the first way I learned to deal with it, and,
even though I subsequently learned about the Count property,
and started using it when I thought of it, the len function
is still the first thing that pops ino my mind.

Naturally. There's certainly a case to be made for convention.

In defense of JScript in ASP, I feel I should point out that this is one
example where the advice possibly hampers the guy trying to do it in
JScript. While there is an analogue for Len() in String.length, there is
none for using the default property.

For this reason, I always strive to use examples that expose object
structure, rather than conceal:

If Len(Request.Form("checkbox_name").Item) > 0 Then ...

(Of course, irony dictates that this example somewhat weakens my point, as
String.length does not apply when there is no name-value pair, and hence no
string)

In any case, it is my belief that VBScript authors will benefit from more
illustrative examples as well as JScript authors, even if it makes no
practical difference in this specific instance. We ALL are better off
understanding the objects we work with.
 

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,777
Messages
2,569,604
Members
45,218
Latest member
JolieDenha

Latest Threads

Top