By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,635 Members | 2,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,635 IT Pros & Developers. It's quick & easy.

CheckAll dynamically generated checkboxes in the page using a checkbox

P: 5
Hi,

I'm creating a PHP application. In this a dynamic table with the fields in the database is generated in a page. I have placed a checkbox in each row of the table to approve/disapprove according to spec. This checkbox is also created dynamically according to the fields in the database. Now I need to place a checkbox/ button (by checking the checkbox all the checkbox in the page has to be checked). I checked online and I was able to find the code only for static checkboxes which does not slove my issue..

I here by attach sample of my code..

$result= mysql_query("select * from info where status != 'processed' ;");

// I need to click on this checkbox placed atlast to check all the checkboxes

if($result) echo "<td>Bid</td><td>Item</td><td>Vendor#</td><td>Vendor Name</td><td>G/L Acct</td><td>Invoice</td><td>Invoice Data</td><td>Date Enter</td><td>Remarks</td><td>To Approve all, Click here<input type=\"checkbox\" name=\"master\"></td>";

while($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<tr>";
// This is the dynamically generated Table with checkbox at last

echo "<td width='10%'><form name=\"formvalid\" action =\"PHP_SELF" method =\"post\" enctype=\"application/x-www-form-urlencoded\" ><input type=\"hidden\" name = \"bld\" value= \"".$line['bld']."\"><input type=\"hidden\" name = \"item\" value= \"".$line['item']."\"><input type=\"hidden\" name = \"vendorno\" value= \"".$line['vendor_no']."\"><input type=\"hidden\" name = \"vendorname\" value= \"".$line['vendor_name']."\"><input type=\"hidden\" name = \"glacct\" value= \"".$line['gl_acct']."\"><input type=\"hidden\" name = \"invoiceno\" value= \"".$line['invoice_no']."\" ><input type=\"hidden\" name = \"invoicedate\" value= \"".$line['invoice_date']."\"><input type=\"hidden\" name = \"remarks\" value= \"".$line['remarks']."\" ><input type=\"checkbox\" name=\"elements\"></input></form></td>";
}

I hope now you would have got a clear picture of whats happening..
Can you pls. help me on this please...

Thanks,
Srikanth
Jun 14 '07 #1
Share this Question
Share on Google+
7 Replies


Motoma
Expert 2.5K+
P: 3,235
Quick question: How are you handling the input from more than one checkbox currently?
Jun 14 '07 #2

P: 5
Quick question: How are you handling the input from more than one checkbox currently?
Thanks for ur reply,

I was having a button befor with approve&deny .. now the client wants me to change it with a check box so that If the checkbox is selected the data will be approved and if not then it is denied.. I'm not sure how to do it..
Jun 14 '07 #3

Motoma
Expert 2.5K+
P: 3,235
You will need to assign each checkbox a value, so that the resulting array will be able to distinguish between them.

I will move this question to the Javascript forum, as that is what you will need to use to perform this action.
Jun 14 '07 #4

P: 5
You will need to assign each checkbox a value, so that the resulting array will be able to distinguish between them.

I will move this question to the Javascript forum, as that is what you will need to use to perform this action.
Thanks for the info.

I understand what you are trying to say but the problem here is you cannot assign each checkbox a value because you will not know how many checkboxes are there in the page. It totally depends on the data in the table. And the number of data keeps changing as the users will add and remove data from table.
Jun 14 '07 #5

Motoma
Expert 2.5K+
P: 3,235
Thanks for the info.

I understand what you are trying to say but the problem here is you cannot assign each checkbox a value because you will not know how many checkboxes are there in the page. It totally depends on the data in the table. And the number of data keeps changing as the users will add and remove data from table.
I understand that, which is why you need to do it programmatically.
Jun 14 '07 #6

P: 5
I understand that, which is why you need to do it programmatically.
Thanks..
Can someone please help me on this..
Jun 14 '07 #7

Motoma
Expert 2.5K+
P: 3,235
Thanks..
Can someone please help me on this..
Just have an integer keeping count of the row number inside your checkbox loop. Or better yet, use the primary key of your table.
Jun 14 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.