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

Link to comment
Share on other sites

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.

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.