Forum Moderators: open
while (list($catid,$description)=mysql_fetch_row($result))
{
$col++;
echo "<td width='50px' align='center' id='dtl_box'>";
echo $description;
echo "<div align='right' valign='bottom'><input type='checkbox' id='catgrp' name='catid[]' value='". $catid. "'></div>";
echo "</td>";
if ($col>5) {
$col=0;
echo "</tr>";
}
}
?>
</td><tr><td colspan='6'>With Selected <input name='delcat' type='button' value='Delete' onclick="javascript:if(chkform(1)){catman(2)}"><input name='resetbutton' type='reset' value='Unselect'></form></tr><tr>
</tr></table>
<?
}
After the user selected the categories by checking the checkboxes, it will ask if he really wanted to delete the categories, then if yes proceed to catman() function.
...
if (vsrc=2) {
var cats= document.getElementById('catgrp').value;
if (cats!='') {
var queryString = "?c=" + cats;
ajaxRequest.open("GET", "killcats.php" + queryString, true);
ajaxRequest.send(null);
this is the portion where it will call killcats.php along with its query string which, I assumed is an array. BUT, there goes the problem, killcats.php can't grab the array value from where it came from and gives an error on mysql query.
any suggestion how to capture array value from the checkboxes ?
Thanks in advance.
...
var cats= document.getElementsByName('catid').value;
...
....
echo "<div align='right' valign='bottom'><input type='checkbox' name='catid[]' value='". $catid. "'></div>";
...
Here's the PHP code :
$selcats=$_REQUEST['c'];
$selcats = implode(',',$selcats);
$qry="delete from usrcategory where `catid` in ".$selcats." and uid=". $_SESSION['uid'];
$result=mysql_query($qry) or die(" may mali $qry!");
Array
(
[c] => undefined
....
)
Anybody suggestions ?
Thanks for the effort.
I created a javascript function that gets all the .checked from checkedboxes then put it in a string.
-----
function getCheckboxValue()
{
var catids="";
for(var el=0; el < document.catfrm.catid.length; el++)
{
if(document.catfrm.catid[el].checked)
{
catids =catids+document.catfrm.catid[el].value+',';
}
}
return catids;
}
----
then I pass the string to PHP script.
Thanks ! :)
ajaxRequest.open("POST", "killcats.php" + queryString, true); ajaxRequest.send(queryString);
ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');