Jump to content

How to find which checkbox(s) selected and get their values ?


htetnainglynn

Recommended Posts

Hi everyone,

 

First time here and learning PHP now. I have a page which includes of several checkboxes based on a table rows. Eg, if my users table has 30 users, there're going to be 30 checkboxes. I am sure you probably hav guessed by now that if the user selected all 30 users, and delete, they all will be deleted in the database. I am having difficulties in how to uniquely identify each checkbox and get the value from each checkbox because I am thinking of storing user_id from the database in each checkbox as value. Any help would be appreciated on this. To my understanding, if one checkbox is selected and i get the value "on" or if there's value in that checkbox i get the value of it in php file but there should be some sort of like arrays to actually loop through the $_POST["inputCheckboxName"] and get selected checkbox's value or something like that ? Any help would be greatly appreciated. Thanks all.

Umm  I found the answer. It does return as an array and we need to declare the name of the checkbox something like name="checkboxNames[]" and retrieve it back from the php file as array For eg.

 

 

for($i = 0 ; $i < count($_POST(["checkboxNames"]) ; $i++)
{
  //do whatever we wanna do
}

 

Hope it helps others who have the same problem like me.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.