sean04 Posted October 21, 2010 Share Posted October 21, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/216512-check-box-remove-all-selected-items/ Share on other sites More sharing options...
btherl Posted October 21, 2010 Share Posted October 21, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/216512-check-box-remove-all-selected-items/#findComment-1125024 Share on other sites More sharing options...
marcus Posted October 21, 2010 Share Posted October 21, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/216512-check-box-remove-all-selected-items/#findComment-1125032 Share on other sites More sharing options...
sean04 Posted October 22, 2010 Author Share Posted October 22, 2010 Thank you both for your replies. mgallforever, it worked perfectly thanks! Thanks, Sean Quote Link to comment https://forums.phpfreaks.com/topic/216512-check-box-remove-all-selected-items/#findComment-1125056 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.