9lessons programming blog
Loading Search
Friday, November 26, 2010

Delete Records with Color Change Effect using jQuery and Ajax

This post is an update of my previous post Delete Records animation effect with jquery. I had added new feature records delete with color change animation effect using jquery beforeSend method and color plugin. It is very useful to display loading status messages or effects before getting the ajax success request.

delete records before color change

Download Script     Live Demo

Database Table Code
A simple database table two columns msg_id and message.
CREATE TABLE updates(
msg_id INT PRIMARY KEY AUTO_INCREMENT,
message TEXT);


jQuery code
Contains javascipt code. $(".delete_button").click(function(){}- delete_button is the class name of anchor tag (X). Using element.attr("id") calling delete button value.
<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js
"></script>
<script type="text/javascript" src="jquery.color.js"></script>
<script type="text/javascript">
$(function() {
$(".delete_button").click(function() {
var id = $(this).attr("id");
var dataString = 'id='+ id ;
var parent = $(this).parent();

$.ajax({
type: "POST",
url: "deleteajax.php",
data: dataString,
cache: false,
beforeSend: function()
{
parent.animate({'backgroundColor':'#fb6c6c'},300).animate({ opacity: 0.35 }, "slow");;
},
success: function()
{
parent.slideUp('slow', function() {$(this).remove();});
}
});

return false;
});
});
</script>

deleteajax.php
Contains PHP code. Delete record from the database.
<?php
include("dbconfig.php");
if($_POST['id'])
{
$id=$_POST['id'];
$id = mysql_escape_String($id);
$sql = "delete from updates where msg_id='$id'";
mysql_query( $sql);
}
?>

CSS Code
You should use background-color here otherwise jquery.color.js could not work.
*{margin:0;padding:0;}
ol.update
{
list-style:none;font-size:1.2em;
}
ol.update li
{
height:50px; border-bottom:#dedede dashed 1px;background-color:#ffffff
}
#main
{
width:500px; margin-top:20px; margin-left:100px;
font-family:"Trebuchet MS";
}
.delete_button
{
margin-left:10px;
font-weight:bold;
float:right;
}
Sponsored Links

Share this post

Comments
{ 24 comments }
Anonymous said...

Nice work thanks

Musti said...

Excellent job man I like your tutorials. I will definitly use this in one of my projects

Anonymous said...

Cool man. :) thanks for this tutorial.

dskanth said...

Too cool... keep it up !

Rich said...

Nice an tidy.

Mike said...

Hi dude, your tutorials are great. Thank you for sharing your knowledge! :)

Bhargav Anadkat said...

It is very nice.

Beben said...

hohohoho nice effect my friend,...
thanks :)

Dominic said...

This work very nice Thanks Dude

Hector said...

good job, easy to implement, thanks

gescheit said...

thanks

Anonymous said...

Thanks for sharing.

barath said...

hi,
kindly provide me php mysql codings to edit records and update.
Thanks.

Anonymous said...

Hy.
Sow do you secure your deleteajax.php file?

Sergiu said...

Hy. I am looking for a solution to secure the deleteajax.php file. Everybody can insert the link to this file in browser and can run that script, and I'm sure that there is a way for downloading that file and this is not ok from the moment that this contains mysql querys. Can you please help me with this problem?

topme said...

Like it! so easy.
Hi from Belarus ;)

Anonymous said...

i can't delete data from my MySql
and how to delete it out of MySql

Anonymous said...

Is anywhere on this website available script for voting "for" and "against". Like in image of this article (green and red thumbs). Thanks.

Anonymous said...

its gr8 script.....thanx....
bt the problem i am facing is that i want to delete tr but this scripts only delete the td part.....plz help me out in this...

Anonymous said...

hey Cool one man .. But its not working for me on IE please help me on this

Nauman Ahmed said...

many thanks bro.. really helped your code and files. going to bookmark your site. Keep sharing nice stuff

Anonymous said...

yeahhhhhhhh regards, Mexico !!

dean said...

i can't delete data from my MySql
and how to delete it out of MySql?

Chirag Shah said...

First of all Thanks Srinivas

its nice job

and others Just put

include("dbconfig.php");


into "deleteajax.php" to delete from mysql

Post a Comment

Subscribe now!Recent Posts

Categories

Subscribe now!Popular Posts

People Says

@9lessons thank you for the great tutorials, we truly appreciate your contributions to the design community.

Smashing Magazine

Like Me

follow me
products

9lessons labs

9lessons clouds

Android application

Chrome Extension