Catching All Checkbox Changes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
montecristo
Forum Newbie
Posts: 20
Joined: Thu Oct 19, 2006 9:51 am

Catching All Checkbox Changes

Post by montecristo »

Hi Guys

Just wondering if you could help me solve this problem. I create a table with values from my database.
The table is dynamically created and each row contains a checkbox

Code: Select all

<td align="center"><input type="checkbox" name=<?echo $i ; ?> value="webyn"></td>
The checkbox is checked or unchecked depending on a value in the database. If you check an unchecked box and press the submit button I can get the checked checkboxes using :

Code: Select all

foreach ($_POST as $key => $value )
	{
                  echo $key;
                }
Which works fine. Now my question! If the checkbox was originally checked and the user unchecks it and then presses the submit button. How can I tell that this button was unchecked?

Thanks in advance for your time
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

You cant tell the checkbox was unchecked directly after the form submission. What you will have to do is compare the new checked values with the previous checked values in the database. Doing this, you should be able to determine which values were unchecked.
montecristo
Forum Newbie
Posts: 20
Joined: Thu Oct 19, 2006 9:51 am

Post by montecristo »

Thanks, that makes a lot of sense!

Thank you for your time
Post Reply