Checking to see if Checked Boxes are Checked

Checking to see if Checked Boxes are Checked

Post by Lyn » Wed, 17 Dec 2003 00:58:28


How do I check to see if a checked box is check on the
following page?

This is what I have. What am I doing wrong?

<%If Request("chkDirection") = 1 Then

Response.Write "True" & Request("PssWrd")
Else
Response.Write "False" & Request("chkDirection") &
Request("PssWrd")
End If%>

chkDirection is a check box from a previous page.

Thank you in advance.

Lyn
 
 
 

Checking to see if Checked Boxes are Checked

Post by Bob Barrow » Wed, 17 Dec 2003 01:25:59


If it is checked, it will have a value. If not, it won't. Assuming the name
property of the checkbox is "chkDirection" then:

<%
if len(Request("chkDirection")) > 0 then
Response.Write "True" & Request("PssWrd")
Else
Response.Write "False" & Request("chkDirection") & _
Request("PssWrd")
End If
%>

ASP questions such as this should be posted to .inetserver.asp.general. If
the question is also database related (in addition to being asp-related), it
should be posted to .inetserver.asp.db

HTH,
Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

 
 
 

Checking to see if Checked Boxes are Checked

Post by McKiraha » Wed, 17 Dec 2003 01:36:15


Consider this approach which uses client-side JavaScript to determine
whether a checkbox is checked or not and assigns the result to a hidden
field then subsequently inspected in the VBScript code upon re-entry to the
page.


<% @Language="VBScript" %>
<% Option Explicit
Const cASP = "checkbox.asp"
If Request.Form("Boxers") = "True" Then
Response.Write("<br>Boxer1: " & Request.Form("Boxer1"))
Response.Write("<br>Boxer2: " & Request.Form("Boxer2"))
End If
%>
<html>
<head>
<title><%=cASP%></title>
<script language="javascript" type="text/javascript">
<!--
function checker(form) {
if (form.Box1.checked) {
form.Boxer1.value = "True";
} else {
form.Boxer1.value = "False";
}
if (form.Box2.checked) {
form.Boxer2.value = "True";
} else {
form.Boxer2.value = "False";
}
form.Boxers.value = "True";
}
// -->
</script>
</head>
<body>
<form action="<%=cASP%>" method="post" onsubmit="checker(this)">
<input type="hidden" name="Boxers" value="False">
<input type="hidden" name="Boxer1">
<input type="hidden" name="Boxer2">
<input type="checkbox" name="Box1" value="checked" checked>
<input type="checkbox" name="Box2" value="unchecked">
<input type="submit" value="Submit">
</form>
</body>
</html>
 
 
 

Checking to see if Checked Boxes are Checked

Post by Dr John St » Wed, 17 Dec 2003 08:58:06

JRS: In article <3qlDb.554653$Tr4.1503586@attbi_s03>, seen in

posted at Mon, 15 Dec 2003 16:36:15 :-



Does form.Boxer1.value = form.Box1.checked not give the
desired effect?

--
< http://www.yqcomputer.com/ ;m> Jsc maths, dates, sources. < http://www.yqcomputer.com/ >/> TP/BP/Delphi/Jsc/&c, FAQ topics, links.
 
 
 

Checking to see if Checked Boxes are Checked

Post by McKiraha » Wed, 17 Dec 2003 10:29:32


4 gt; >< http://www.yqcomputer.com/ ;/> Jim Ley's FAQ for

sources.> >< http://www.yqcomputer.com/ >/> TP/BP/Delphi/Jsc/&c, FAQ topics,
links.


Yes. I was showing the OP an example not knowing what may be used for
"value=".