Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 20th, 2004, 01:19 PM
Friend of Wrox
Points: 1,035, Level: 12
Points: 1,035, Level: 12 Points: 1,035, Level: 12 Points: 1,035, Level: 12
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , USA.
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default 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
Reply With Quote
  #2 (permalink)  
Old January 20th, 2004, 01:44 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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.
Reply With Quote
  #3 (permalink)  
Old January 20th, 2004, 02:48 PM
Friend of Wrox
Points: 1,035, Level: 12
Points: 1,035, Level: 12 Points: 1,035, Level: 12 Points: 1,035, Level: 12
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , USA.
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default


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>
Reply With Quote
  #4 (permalink)  
Old January 20th, 2004, 03:32 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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
Reply With Quote
  #5 (permalink)  
Old January 20th, 2004, 05:24 PM
Friend of Wrox
Points: 1,035, Level: 12
Points: 1,035, Level: 12 Points: 1,035, Level: 12 Points: 1,035, Level: 12
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , USA.
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default

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
Reply With Quote
  #6 (permalink)  
Old January 20th, 2004, 06:31 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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.
Reply With Quote
  #7 (permalink)  
Old January 23rd, 2004, 11:19 AM
Registered User
 
Join Date: Jan 2004
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checkbox checked all mateenmohd Javascript 1 January 2nd, 2007 06:19 AM
checkbox checked by default by html:checkbox sachin.tathod Struts 3 December 4th, 2006 03:41 PM
Checkbox checked? ninel ASP.NET 2.0 Professional 1 April 12th, 2006 10:50 PM
Display every checkbox checked InsouciantCoquette Classic ASP Components 0 February 10th, 2006 04:02 AM
allow only one checkbox to be checked! morpheus HTML Code Clinic 5 April 15th, 2004 10:59 AM



All times are GMT -4. The time now is 06:55 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.