Jump to content

Check Box - Remove All Selected Items


sean04

Recommended Posts

I have say about 7 different interests and beside each interest I want a check box. How would I go about having multiple check boxes checked so I can remove however many interests at one time...

 

For example:

 

[Checked] Hockey

                Soccer

                Baseball

[Checked] Basketball

 

And the remove all selected button would remove the checked interests.

 

Thanks,

Sean

 

 

Link to comment
https://forums.phpfreaks.com/topic/216512-check-box-remove-all-selected-items/
Share on other sites

There's numerous javascript implementations of this.  If you google for something like "javascript check multiple checkboxes" you'll see quite a few.

 

If you want specific advice on how to implement it for your page, I think we would need to see the html you are using.

Why would you need to use Javascript for this? It's simply just using

 

<input type="checkbox" name="interest[]" value="hockey">

 

for all interests.

 

<form method="post">
    <input type="checkbox" name="interest[]" value="hockey" />Hockey<br />
    <input type="checkbox" name="interest[]" value="soccer" />Soccer<br />
    <input type="checkbox" name="interest[]" value="baseball" />Baseball<br />
    <input type="checkbox" name="interest[]" value="basketball" />Basketball<br />
    <input type="submit" name="submit" value="Delete Selected Interested" />
</form>
<?php
if($_POST['submit']){
    $interests = $_POST['interest'];
    if(count($interests) > 0){
        foreach($interests AS $interest){
            $sql = "DELETE FROM `interests` WHERE `interest`='".mysql_real_escape_string($interest)."'";
            $res = mysql_query($sql) or die(mysql_error());
            echo htmlentities($interest) . " has been removed!";
        }
    }
}
?>

 

Obviously other security measures could be implemented.

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.