 |
| Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 20th, 2004, 01:19 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Display Checkbox if checked or not
Let's say that a user comes in and checks the checkbox, saves it and goes back to see if it took. How can I display a check in a checkbox?
<TR>
<TD><b>Join List : </TD>
<TD><INPUT TYPE="CheckBox" NAME="JoinList" VALUE <%= Session("JoinList") %> "SIZE="40" ><b>E-mail me Fund News and Events</b>
</TD>
</TR>
I went ahead and checked the box as a test if it is checked or not. I see the it is checked. I just don't know how to display the value. If somebody can please help me write the code.
<% If session("joinlist") = checked then
response.write "Joinlist " & session("JoinList") & "<BR>"
checkbox = "vbchecked"
else
response.write "empty"
end if %>
Thanks,
Judy
|
|

January 20th, 2004, 01:44 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
You just need to tell the checkbox that it is "checked":
<INPUT TYPE="CheckBox" NAME="JoinList" VALUE="<%= Session("JoinList") %>" SIZE="40" checked>
I also fixed your "value" attribute that didn't look right.
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

January 20th, 2004, 02:48 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Peter,
I am checking the value whether the box is checked or not. So the following is my code to display a check on the checkbox. My problem is whether or not it is checked, it displays a check in the box. What is wrong with my "If" statement?
Thanks,
Judy
<TD><b>Join List : </TD>
<% If Session("JoinList") = checked Then %>
<TD><INPUT TYPE="CheckBox" NAME="JoinList" VALUE <%= Session("JoinList") %> "SIZE="40" checked><b>E-mail me Fund News and Events</b>
<% Else %>
<TD><INPUT TYPE="CheckBox" NAME="JoinList" VALUE <%= Session("JoinList") %> "SIZE="40"><b>E-mail me Fund News and Events</b>
<% End If %>
</TD>
|
|

January 20th, 2004, 03:32 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
I'm not sure why you are checking the Session collection for a value, I was assuming that you were saving the checked state of the check box into that and that it contained the value you wanted to check for the "checked" state of the checkbox. If you just want to see the state of the checkbox that is posted, you need to use Request("...").
Here's how I'd do this:
<TD><b>Join List : </TD>
<%
Dim sJoinListChecked : sJoinListChecked = ""
If <condition to test for checkbox state> Then
sJoinListChecked = "checked"
End If
%>
<TD>
<INPUT TYPE="CheckBox" NAME="JoinList" SIZE="40" <%=sJoinListChecked%>>
<b>E-mail me Fund News and Events</b>
</TD>
Peter
|
|

January 20th, 2004, 05:24 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The reason I am validating the session variable Joinlist is because on the previous page I read it all the fields to session variables and am displaying on a different page. My problem is I can't seem to display the checkbox correctly, if the field joinlist is true, it should display a check on the checkbox. This is why I am checking the session variable joinlist. Having said this, is there a proper way of handling this scenario?
Thanks,
Judy
|
|

January 20th, 2004, 06:31 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Just use Session("JoinList") as your if test:
<TD><b>Join List : </TD>
<%
Dim sJoinListChecked : sJoinListChecked = ""
If Session("JoinList") Then
sJoinListChecked = "checked"
End If
%>
<TD>
<INPUT TYPE="CheckBox" NAME="JoinList" SIZE="40" <%=sJoinListChecked%>>
<b>E-mail me Fund News and Events</b>
</TD>
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

January 23rd, 2004, 11:19 AM
|
|
Registered User
|
|
Join Date: Jan 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
If you have multiple Check/Radio boxes you might like to use a function for the job:
Function IsChecked (WhichField, FieldValue)
If Request.Form(WhichField)=FieldValue then
IsChecked="CHECKED"
Else
IsChecked=""
End If
End Function
Then I'd call it like this:
<input type=radio name="chrTypeOfPhone" value="Home" <%=IsChecked ("chrTypeOfPhone","Home")%>>Home
<input type=radio name="chrTypeOfPhone" value="Work" <%=IsChecked ("chrTypeOfPhone","Work" )%>>Work
<input type=radio name="chrTypeOfPhone" value="Mobile" <%=IsChecked ("chrTypeOfPhone","Mobile")%>>Mobile
This particular example checks against form data, but you could easily modify it to check against recordset data, session data etc.
|
|
 |