function removeElement(divRemove) { $(divRemove).fadeOut(1000); } function theResult(data, popuDivDel) { var popuDiv = popuDivDel; $(popuDiv).removeClass('success'); //remove the classes to avoid overlapping $(popuDiv).removeClass('error'); //remove the classes to avoid overlapping //If var success received from the php file is 0, then that means there was an error if(data.success == 0) { $(popuDiv).html(data.message); //attach the message to the div $(popuDiv).addClass('error'); //attach the error class to the result div to show the errors //Add a link to dismiss the errors $(popuDiv).prepend('<a href=\"javascript:;\" onclick=\"removeElement(\''+popuDiv+'\')\"><img src="images/dismiss.png" alt="Dismiss Errors" title="Dismiss Errors" width="20" height="20" align="right" /></a>'); } else if(data.success == 1) //means that our submission was good { $(popuDiv).html(data.message); //attach the message to the div $(popuDiv).addClass('success'); //attach the success class to the result div to show success msg setTimeout(function(){ $(popuDiv).fadeOut('slow'); }, 2000); //attach the animated effect as well } } $(document).ready(function() { $().ajaxStart(function() { $('#loading').show(); $('#result').hide(); $('#loading_todo').show(); $('#result_todo').hide(); }).ajaxStop(function() { $('#loading').hide(); $('#result').fadeIn('slow'); $('#loading_todo').hide(); $('#result_todo').fadeIn('slow'); }); $('#myForm').submit(function() { $.ajax({ type: 'POST', url: $(this).attr('action'), data: $(this).serialize(), dataType: 'json', success: function(data) //trigger this on successful reception of the vars from the php file { var popuDiv2 = '#result'; theResult(data, popuDiv2); } }) return false; }); $('#frm_todo').submit(function() { $.ajax({ type: 'POST', url: $(this).attr('action'), data: $(this).serialize(), dataType: 'json', success: function(data) //trigger this on successful reception of the vars from the php file { var popuDivDel = '#result_todo'; theResult(data, popuDivDel); } }) return false; }); }) ToDo Form Enter to-do item: REGISTER Form Name