473,387 Members | 1,925 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.

Updating a count of checkboxes that are checked

There is a Summary/Example further down...

On page one of my site I have a form with some checkboxes and detailed
descriptions. When the form is submitted (to page two), the values of
the checkboxes are picked up using $_POST and put into session
variables. On page two there is another form which is simply a
condensed version of the previous one (titles with no descriptions).
The checkboxes are named the same on both forms.

When page two loads and the posted variables have been put into session
variables, my PHP script loops through the session variables and sets
the checkboxes on the form to checked where there is a corresponding
session variable set. I also have a variable which counts how many of
the checkboxes are checked. This is incremented when a session variable
that is set (checkbox will be checked) is encountered. So far, so good
as this all works with no problems.

Now to the problem. I need the users to be able to check/uncheck the
checkboxes on page two if they change their mind or made a mistake on
page one. If they amend any checkboxes then they can press an Update
button to update the count variable.

Normally I would achieve this by posting the form back to the page
containing the script however once the form on page two is finalised, it
needs to be posted to a third page which lays out the data for printing.
This does not use form items so the third page is necessary.

Example of what I need/Summary of my waffle above:

Page 1:User checks 3 boxes and submits form to page 2
Page 2:Item count shows 3 items. User adds 2 more items and presses
Update button. Item count now shows 5 items. "New" checkboxes remain
checked.
Page 2:User is happy and submits form to page 3
Page 3:Form items are converted into printable text/data

Is there a way to submit a form to one location if one button is pressed
and another location if a second button is pressed? I'm guessing "No"
as a form's "action" can only be one location.

Any ideas?

Thanks in advance,

Pete.

Jul 17 '05 #1
2 3947
Pete wrote:
Is there a way to submit a form to one location if one button is pressed
and another location if a second button is pressed? I'm guessing "No"
as a form's "action" can only be one location.


You can name your submit buttons differently and act on which button was
pressed.

<input type="submit" name="sumbit" value="Preview">
<input type="submit" name="sumbit" value="Go!">
<!-- this misspelling ^^^^^^ was deliberate :) -->

and the receiving PHP could do

<?php
// save $_POST data
$_SESSION['postdata'] = $_POST;
switch ($_POST['sumbit']) {
case 'Preview' : $URL = 'http://www.example.com/page1.php';
break;
case 'Go!': $URL = 'http://www.example.com/page2.php';
break;
default: $URL = false;
}
if ($URL) {
header('Location: ' . $URL);
exit('Redirected <a href="' . $URL . '">here</a>.');
} else {
// Uh Oh, someone must have been playing with my form
}
?>
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
In article <DV***************@news-binary.blueyonder.co.uk>,
Pete <skredding_no_spam_you_tw@s_netscape.net> wrote:
There is a Summary/Example further down...

On page one of my site I have a form with some checkboxes and detailed
descriptions. When the form is submitted (to page two), the values of
the checkboxes are picked up using $_POST and put into session
variables. On page two there is another form which is simply a
condensed version of the previous one (titles with no descriptions).
The checkboxes are named the same on both forms.

When page two loads and the posted variables have been put into session
variables, my PHP script loops through the session variables and sets
the checkboxes on the form to checked where there is a corresponding
session variable set. I also have a variable which counts how many of
the checkboxes are checked. This is incremented when a session variable
that is set (checkbox will be checked) is encountered. So far, so good
as this all works with no problems.

Now to the problem. I need the users to be able to check/uncheck the
checkboxes on page two if they change their mind or made a mistake on
page one. If they amend any checkboxes then they can press an Update
button to update the count variable.

Normally I would achieve this by posting the form back to the page
containing the script however once the form on page two is finalised, it
needs to be posted to a third page which lays out the data for printing.
This does not use form items so the third page is necessary.

Example of what I need/Summary of my waffle above:

Page 1:User checks 3 boxes and submits form to page 2
Page 2:Item count shows 3 items. User adds 2 more items and presses
Update button. Item count now shows 5 items. "New" checkboxes remain
checked.
Page 2:User is happy and submits form to page 3
Page 3:Form items are converted into printable text/data

Is there a way to submit a form to one location if one button is pressed
and another location if a second button is pressed? I'm guessing "No"
as a form's "action" can only be one location.


<input type='submit' value='Send'
onClick="document.form.action='page.php';document. form.submit();" />
<input type='submit' value='Next'
onClick="document.form.action='form2.php';document .form.submit();" />

That should do it. But you should ask in a JavaScript group.

--
Sandman[.net]
Jul 17 '05 #3

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

Similar topics

4
by: Pete | last post by:
Okay, I'm still stuck with this problem. Here's a quick recap/summary :- 1. Page 1:User checks 3 out of 10 checkboxes and submits form to page 2 2. Page 2:Item count shows 3 items. User checks...
4
by: Laura | last post by:
Here's the situation: I'm trying to use an update query to copy data from one row to another. Here is the situation: I have 5 companies that are linked to each other. I need to show all 5...
0
by: willow1480 | last post by:
I am developing a small little Service Control Application. I am using a listview control with checkboxes and getting the list of services I want to control from a text file. When you check a...
0
by: dan_williams | last post by:
I have an ASP.NET web page with a CheckBoxList which users can select multiple checkboxes and select to save, which inserts a record/row for each checkbox ticked into an SQL database. What is...
1
by: Christian Rühl | last post by:
hey! what i wanna do sounds very simple at first, but it turned out to be a real bone crusher... i want to check if a treeView node is checked and if a correspondent node in my xml config file...
4
by: haresh.amis | last post by:
hello to all, I m using .net 2.0 and i face a problem that is as under Well I have a checkboxlist which i bound in .cs page now I want to count that how many checkboxes ate checked ( In...
10
by: chimambo | last post by:
Hi All, I have a little problem. I am retrieving records from a table and I want to update the records using checkboxes. I am able to display the database record quite alright and I have created...
0
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
14
by: zufie | last post by:
I have to create a QA report regarding callers calling into a phone hotline. The report consists of many checkboxes such as: Did the IBCCP agency contact you? Yes/NO How many days passed...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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,...

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.