473,387 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 5446
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
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....
2
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...
1
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...
0
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...
3
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? ...
7
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") =...
0
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...
0
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,...
3
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.