CodeIgniter Forums
Delete Selected Checkbox items from the database. HELP - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Delete Selected Checkbox items from the database. HELP (/showthread.php?tid=24205)



Delete Selected Checkbox items from the database. HELP - El Forum - 11-03-2009

[eluser]basty_dread[/eluser]
How could I delete the selected checkbox with coresponding value from the database?
Anyone please help me. Thank you very much.

here is my code for the checkbox
i wonder how could i know the checked items and then Delete the items from the database
Code:
<form name="form1">
<?
for($i = 0; $i < sizeof($primeno); $i++){

?&gt;
&lt;input type="checkbox" name="rdindex1" value="&lt;?=$primeno[$i];?&gt;"/&gt;

&lt;?
}
?&gt;

&lt;input type="submit" name="delete" value="Delete Selected"&gt;
&lt;/form&gt;



Delete Selected Checkbox items from the database. HELP - El Forum - 11-03-2009

[eluser]basty_dread[/eluser]
Please help me on my problem. Thank you


Delete Selected Checkbox items from the database. HELP - El Forum - 11-03-2009

[eluser]bigtony[/eluser]
Change the input field name into an array:
Code:
// change this
&lt;input type="checkbox" name="rdindex1" value="&lt;?=$primeno[$i];?&gt;"/&gt;

// to this
&lt;input type="checkbox" name="rdindex1[]" value="&lt;?=$primeno[$i];?&gt;"/&gt;
Then when you read it in your controller the value passed back in $this->input->post('rdindex1') will be an array you can loop through.


Delete Selected Checkbox items from the database. HELP - El Forum - 11-03-2009

[eluser]basty_dread[/eluser]
thank's for posting bigtony how about checking if the checkbox is checked or not?
Thanks.


Delete Selected Checkbox items from the database. HELP - El Forum - 11-03-2009

[eluser]marjune[/eluser]
in the page where you submit, just make a loop to check the checked box

Code:
&lt;?
   for($i = 0; $i < sizeof($primeno); $i++){
      
      if(isset($primeno[$i]))
           //primeno[$i] is checked
   }
?&gt;



Delete Selected Checkbox items from the database. HELP - El Forum - 11-03-2009

[eluser]basty_dread[/eluser]
i can't get it on how to use javascript to check all or uncheck the checkboxes using this name with brackets

Code:
&lt;input type="checkbox" name="rdindex1[]" value="&lt;?=$primeno[$i];?&gt;"/&gt;

the javascript only works if the
Code:
name="rdindex1"

what should i do?
this is my javascript for checking all the checkbox:
Code:
function checkallBox()
{
    for (i=0;i<document.forms['formkeywords'].rdindex1.length;i++)
    {
        document.forms['formkeywords'].rdindex1[i].checked=true;
                                                                       }
}



Delete Selected Checkbox items from the database. HELP - El Forum - 11-03-2009

[eluser]bigtony[/eluser]
Why do you need to process it in JavaScript?


Delete Selected Checkbox items from the database. HELP - El Forum - 11-03-2009

[eluser]basty_dread[/eluser]
just like in yahoo mail. there is one checkbox that checked all the checkboxes. and when it uncheck the checkboxes... and when you press delete it will delete all the checked items.


Delete Selected Checkbox items from the database. HELP - El Forum - 03-23-2010

[eluser]bianchi[/eluser]
how about the controller and the model??