ridgey28 Posted December 1, 2010 Share Posted December 1, 2010 Hi I am trying to get data from selected checkboxes using jQuery $post and then getting the values using PHP to delete from a database. I also would like a confirmation dialog to see if the user wants to delete the events. I have looked at various methods on the web but I keep getting stuck. I know a bit about jQuery but not a lot about ajax. Any pointers will be appreciated. Here is the code so far. list.phpLists the events <form name='delete_form' action='' method='post'> <input type="checkbox" value="131" name="deleteCB[]" class="cb" /> <input type="checkbox" value="32" name="deleteCB[]" class="cb" /> <input type="checkbox" value="129" name="deleteCB[]" class="cb" /> <input type='submit' id='deleteBtn' value='Delete' name='DeleteBtn' /> </form> list.js Not sure if any of this is correct! $(document).ready(function(){ $("#deleteBtn").click(function() { var confirmation = confirm("Are You Sure You Want to Delete These Events?") if(confirmation == true) { $(':checkbox:checked').each(function() { $.post('process.php', { deleteCB: $(this).attr('value') }, function(msg){$('.result').html(msg); alert('Items were successfully deleted.')}); }); } else { return false; } }); }); process.phpProcess the deletion of events $value=$_POST['deleteCB']; $db->connect(); $query_delete = "DELETE FROM events WHERE id='$value'"; $db->query($query_delete); $db->close(); Thanks in advance Link to comment https://forums.phpfreaks.com/topic/220403-passing-data-via-jquery-to-delete-data-from-a-mysql-database/ Share on other sites More sharing options...
brianlange Posted December 2, 2010 Share Posted December 2, 2010 Change the submit button to type="button" or if you want to use the submit button prevent the form from submitting when the submit button is clicked. $('#delete_form').submit(function() { return false; }); In my example the process.php page just returns $_POST['deleteCB']; Example: http://www.realtown.com/test9.php Link to comment https://forums.phpfreaks.com/topic/220403-passing-data-via-jquery-to-delete-data-from-a-mysql-database/#findComment-1142368 Share on other sites More sharing options...
ridgey28 Posted December 3, 2010 Author Share Posted December 3, 2010 Thank-you very much. I knew there was something missing but I just couldn't put my finger on it. Link to comment https://forums.phpfreaks.com/topic/220403-passing-data-via-jquery-to-delete-data-from-a-mysql-database/#findComment-1142704 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.