Solved

Deleting Session Variables with Checkbox - 500 points

Posted on 2004-11-01
158 Views
Last Modified: 2013-12-24
We are currently using client variables to set the search criteria for our search pages and we would like to move them over to session variables due to the database load they are putting on our SQL server.  I have been successful moving over some of the variables to session variables, but I am getting stuck on session variables that are being set through the use of a check box on a form.  

Once I check the checkbox, the session variable intdata is set, but when I try to uncheck the intdata checkbox, the box stays checked.  This is the same code that is used for the client variables and they check and uncheck correctly.  What am I missing????

Below is some of the code that sets the variable and the code of the form with the checkboxes.  I have been trying to use the StructDelete for the intdata variable, but it doesn't seem to be deleting the session variable.  

Setting and Deleting the Variable

<!--- Int Data --->
<CFIF isdefined("form.intdata")>
<cflock timeout="30" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
      <CFSET session.intdata = 1>
</cflock>
</cfif>

<CFIF isdefined("url.keepInt") and isdefined("session.intdata")>
      <CFELSEIF not isdefined("form.intdata") and isdefined("session.intdata")>
            <cflock timeout="30" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
                  <CFSET StructDelete (session, "intdata")>
            </cflock>
</cfif>


Code of the form with checkbox.

<form action="InterestForm.cfm" method="post" name="Form">
<table width="100" border=1 bordercolor="000000" cellpadding=0 cellspacing=0 bgcolor="AFCEE2">
      <tr>
            <td>
                  <table>
                  <tr>
                  <td>
                  <input type ="checkbox" name="IntData" value="0" onClick="int_onchange()" <CFIF isdefined("session.intdata")> Checked</cfif>>
                  </td>
                  <td align="center" >Data
                  </td>
                  </tr>
                  <tr>
                  <td>
                  <input type ="checkbox" name="IntPeople" value="0" onClick="int_onchange()" <CFIF isdefined("client.intpeople")> Checked</cfif>>
                  </td>
                  <td align="center">People
                  </td>
                  </tr>
                  <tr>
                  <td>
                  <input type ="checkbox" name="IntThings" value="0" onClick="int_onchange()" <CFIF isdefined("client.intthings")> Checked</cfif>>
                  </td>
                  <td align="center">Things
                  </td>
                  </tr>
                  </table>
            </td>
      </tr>
</table>
</form>

If there is more information that you need, please let me know.

Thanks,

Tobin      
0
Question by:TobinLewis
    7 Comments
     
    LVL 22

    Expert Comment

    by:pinaldave
    Hi TobinLewis,
     
    how about trying this StructClear(session.intdata);

    Regards,
    ---Pinal
    0
     

    Author Comment

    by:TobinLewis
    Hi,

    When I tried StructClear(session.intdata) I received the following error.

    An error occurred while evaluating the expression:

    StructClear(session.intdata)

    Error near line 26, column 9.
    --------------------------------------------------------------------------------

    Cannot convert given value to a struct. Please check the validity of the expression

    0
     
    LVL 22

    Expert Comment

    by:pinaldave
    StructClear(session) if you do this compolite structure will be cleared.
    0
     

    Author Comment

    by:TobinLewis
    Hi,

    I ended up trying the same code that I started with and it seems to be working now.

    <CFIF isdefined("url.keepInt") and isdefined("session.intdata")>
          <CFELSEIF not isdefined("form.intdata") and isdefined("session.intdata")>
          <cflock timeout="30" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
                <CFSET StructDelete(session,"intdata")>
          </cflock>
    </cfif>

    Thanks for your help.

    Tobin
    0
     
    LVL 22

    Expert Comment

    by:pinaldave
    =)
    0
     
    LVL 17

    Expert Comment

    by:Tacobell777
    Do not use StructClear(session.intdata), its actually structClear( session )
    because it clears the whole session scope including CFTOKEN etc.. use structDelete as you have it..

    Best thing to do is set everything in another structure, example;

    <cfset session.savedData = structNew() />
    <cfset session.savedData.something1 = "some data 1" />
    <cfset session.savedData.something2 = "some data 2" />
    <cfset session.savedData.something3 = "some data 3" />

    You can call it like #session.savedData.something3# and you can delete everything with one line of code
    <cfset structDelete( session, "savedData" ) />

    Having said all that, saving search criteria in the session scope is not a good idea at all, its best to pass this on via the form scope.
    0
     

    Accepted Solution

    by:
    PAQed with points refunded (500)

    modulo
    Community Support Moderator
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
    Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    846 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now