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;
}
}

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

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.