473,749 Members | 2,486 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unsetting session variables when a checkbox is set to unchecked

I have some session variables which get set on page one of my site. I
can set an unset these by passing through a parameter in some URL's.
When the user goes to the second page some checkboxes are checked if
their corresponding session variable is set and has a value of "true".

The problem I have is that if the user unchecks a checkbox before
finally moving to page three (which is perfectly okay for them to do if
they wish) then I need to unset the session variable. It's not a
problem if it goes from unchecked to checked as I can check for the
value of the checkbox in page 3 and if it's set then I can set the
corresponding session variable however as an unchecked checkbox is not
sent through as part of the $_POST array then I obviously can't do a
check for it. What I really need to do is alter the session variable as
soon as they update the checkbox.

Can anyone help? I can kind of think of a solution but it involves
JavaScript (again) but that's a story for a different newsgroup...

Thanks,

Pete.

Jul 17 '05 #1
1 5484
Pete wrote:
The problem I have is that if the user unchecks a checkbox before
finally moving to page three (which is perfectly okay for them to do if
they wish) then I need to unset the session variable. It's not a
problem if it goes from unchecked to checked as I can check for the
value of the checkbox in page 3 and if it's set then I can set the
corresponding session variable however as an unchecked checkbox is not
sent through as part of the $_POST array then I obviously can't do a
check for it. What I really need to do is alter the session variable as
soon as they update the checkbox.


Instead of checking checkboxes within the $_POST array do that within
the $_SESSION array

<?php
foreach ($_SESSION['checkbox'] as $k=>$dummy) {
if (isset($_POST[$k])) $_SESSION['checkbox'][$k] = true;
else $_SESSION['checkbox'][$k] = false;
}
?>

Just remember to name your HTML checkboxes the same as your
$_SESSION['checkbox'] indexes


<?php // form output
$_SESSION['checkbox']['cb1'] = true;
echo '<input type="checkbox" name="cb1" checked>';
// ...
?>
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3308
by: Terry | last post by:
When launching our application with Internet Explorer already opened, but not pointing to our web server, the session variables disappear. If you open I.E. after launching our app, it works fine. It also works fine if you have the option set to 'Reuse Windows for Lauching Shortcuts' checked in the I.E. properties and launch our app from a shortcut, but it fails it you launch it from the I.E. favorites or some other method that won't take...
2
1760
by: baylor | last post by:
We have numerous pages that store datasets in Session. Sometimes these are used for one page, sometimes for a few (ex. - search page looks up your info, edit person page edits that info) What i'd like is a way to get rid of these session variables when we no longer need them. We originally trie putting cleanup code in Unload but then realized unload gets called after every page hit, including postbacks, so it wipes out data the active...
1
2413
by: dsmith-nospam | last post by:
Hello, It would be great if someone knows the answer to this problem I'm getting bogged down with it. Basically I'm working with an ASP.NET solution that uses the Session object to maintain state. When I use IIS to browse the .aspx pages the session state works but when I step through the code with Visual Studio's debugger the session variables are lost although the session ID stays the same. When I say the session variables are lost,...
0
1037
by: Daniel Smith | last post by:
Some more information. The reason for the variables being lost is that the Session_Start event is being called several times and this then clears the variables but not the Session Id. The project is an existing project and because the session object and the Context object is used in many different places it isn't realistic to alter this for the sake of getting the project to work well in debug mode.
3
2539
by: Michael | last post by:
Hi, If I use SQL Server to store session state, whenever I call Session is there a call to SQL Server? Even if I call Session a few times in the same Web page, or even the same code block? I'm asking because if there is one SQL Server call every time I have Session, then I should store that in a local variable, right?
7
14637
by: Kermit Piper | last post by:
Hello, How can you clear session variables when a reset button is pressed? I thought I might be able to do something like: <% If request.form("Reset") = "Reset" then Session("variable") = Null %>
0
1716
by: Linda W. | last post by:
Hi, I would appreciate any insight into the following issue.. I have an asp.net application with crystal reports being displayed.. All works fine from my IDE & I am trying to move the app to a test server. The report parameters are input on the first aspx page and I store them in the Session object & use a Server.Transfer() to get to the page that displays the crystal report. The report parameters are all successfully passed to...
0
992
jhardman
by: jhardman | last post by:
Ever heard of this problem before? It's new to me. I'm just posting a link to this thread so discussion will stay in one place, originally posted in ASP forum, and it sounds like an ASP issue, although the OP is using ASP.NET Jared
3
4230
by: spoonybard | last post by:
Hi Everyone, I have a .Net 2.0 C# web application that has important information stored in Sessions that needs to be deleted when the user closes the browser. I know of three ways a user can close their browser: Presses "X" button in top right of browser Presses Alt-F4 From browser menu selects File -> Close With javascript I am able to detect that the user presses the X button. Since Javascript is client side and ASP.Net is server...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9566
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8256
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.