ridgey28
12-02-2010, 01:41 PM
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.
list.php
<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>
lit.js Not sure if 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.php
$value=$_POST['deleteCB'];
$db->connect();
$query_delete = "DELETE FROM events WHERE id='$value'";
$db->query($query_delete);
$db->close();
Thanks in advance
list.php
<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>
lit.js Not sure if 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.php
$value=$_POST['deleteCB'];
$db->connect();
$query_delete = "DELETE FROM events WHERE id='$value'";
$db->query($query_delete);
$db->close();
Thanks in advance