i have this code for view cats of my script
<table align="center" width="100%" cellpadding="0" cellspacing="0" border="0">
<td class="td1" width="70%" align="center">title</td>
<td class="td2" width="30%" align="center">Delete</td>
</tr>
<?php
$select_cats = $mysqli->query("SELECT * FROM cats");
$num_cats = $select_cats->num_rows;
while ($rows_cats = $select_cats->fetch_array(MYSQL_ASSOC)){
$id_cat = $rows_cats ['id'];
$title_cat = $rows_cats ['title'];
?>
<tr rel="<? echo $id_cat; ?>">
<td class="td1" width="70%" align="center"><a class="link2" href="../cat-<? echo $id_cat; ?>.html" target="_blank"><? echo $title_cat ; ?></a></td>
<td class="td2" width="30%" align="center">
<a rel="<? echo $id_cat; ?>" class="deletecat" href="#">Delete Cat</a>
<span class="loading" rel="<? echo $id_cat; ?>"></span>
</td>
</tr>
<?
}
?>
and i use this jquery code for delete cat
<script type="text/javascript">
$(document).ready(function(){
$(".deletecat") .click(function(){
var id_cat = $(this).attr('rel');
var s = {
"id_cat":id_cat
}
$.ajax({
url:'action/delete_cat.php',
type:'POST',
data:s,
beforeSend: function (){
$(".loading[rel="+id_cat+"]") .html("<img src=\"../style/img/load.gif\" alt=\"Loading ....\" />");
},
success:function(data){
$("tr[rel="+id_cat+"]") .fadeOut();
}
});
return false;
});
});
</script>
i want to make verification message in dialog box by alert();
has two options if click Yes do jquery code and if click no close dialog box
thanks
You can use the confirm() dialog to ask the user to confirm the action, if not confirmed exit without the jQuery action like
$(document).ready(function () {
$(".deletecat").click(function () {
//show the confirmation
if(!confirm('do you want to proceed')){
return
}
var id_cat = $(this).attr('rel');
var s = {
"id_cat": id_cat
}
$.ajax({
url: 'action/delete_cat.php',
type: 'POST',
data: s,
beforeSend: function () {
$(".loading[rel=" + id_cat + "]").html("<img src=\"../style/img/load.gif\" alt=\"Loading ....\" />");
},
success: function (data) {
$("tr[rel=" + id_cat + "]").fadeOut();
}
});
return false;
});
});
You can add this code before the ajax connection,
if (!confirm("Are You Sure?")) {
return false;
}
Do this
$(document).ready(function(){
$(".deletecat") .click(function(){
confirm here
if(!confirm("Are you sure you want to delete?")){
return; // i.e return if user selects no. otherwise proceed.
}
var id_cat = $(this).attr('rel');
var s = {
"id_cat":id_cat
}
$.ajax({
url:'action/delete_cat.php',
type:'POST',
data:s,
beforeSend: function (){
$(".loading[rel="+id_cat+"]") .html("<img src=\"../style/img/load.gif\" alt=\"Loading ....\" />");
},
success:function(data){
$("tr[rel="+id_cat+"]") .fadeOut();
}
});
return false;
});
});