Jump to content

[SOLVED] Problem with array of check boxes


rondog

Recommended Posts

Ok I am trying to accomplish two things and I cant seem to get both of them to work together.

 

I have a series of check boxes..When I submit, I need to put all the ones that are checked into an array..thats fine if I name each checkbox 'list[]'.

 

They echo out perfectly.

 

The problem is now my select all and deselect all dont work. I get a syntax error because they are named 'list[]' and not 'list'

 

Any idea on how to do both??

 

my php to get each value of the selected check boxes:

<?php
if(isset($_POST['review']))
{
$list = $_POST['list'];
while(list($key,$val) = @each($list))
{
	echo "$val, ";
}
}
?>

 

 

my javascript to select all/deselect all:

function checkAll(field) {
for (i = 0; i <field.length; i++) {
	field[i].checked = true;
}
}
function uncheckAll(field) {
for (i = 0; i <field.length; i++) {
	field[i].checked = false;
}
}

Link to comment
Share on other sites

Give them a name and id?

name="list[]" for PHP, and id="list" for javascript?

 

I'm 99% sure you can make your funcs get elements by id or something similar.

 

edit: or possibly what you already have would work if you use the id like I mentioned above

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.