I wrote a php code in which when I click on submit button some item in combobox will be deleted. Now I want confirmation and I wrote below code which is not working. php code:
$DeleteButton=$_REQUEST['DeleteButton'];
if ($DeleteButton=="delete") :
if ($DeleteComboBox=="PickOne") :
$DeleteButton = "" ;
else :
$query = "DELETE FROM `items` WHERE `id` = $DeleteComboBox LIMIT 1";
$result = mysql_query($query)
or die("Database deletion failed");
$DeleteButton = "" ;
endif ;
endif ;
echo "<BR><BR><FORM NAME=\"EditFORM\" ACTION=\"./index.php\" METHOD=POST>
";
$sql_select = "SELECT * FROM items WHERE id>0 order by name" ;
$sql_result = mysql_query($sql_select)
or die ("Couldn't execute SQL query on db table.") ;
echo "<SELECT ID=\"DeleteComboBox\" NAME=\"DeleteComboBox\">";
echo "<OPTION VALUE=\"PickOne\" SELECTED>select item</OPTION>";
while ($row = mysql_fetch_array($sql_result)) {
echo "<OPTION VALUE=\"$row[0]\">" . $row[2] . " " . $row[1] . "</OPTION>";
}
echo "</SELECT>";
echo "<BR><BR><INPUT TYPE=SUBMIT NAME=\"DeleteButton\" VALUE=\"delete\" ID=\"DeleteButton\">
" ;
echo "</FORM>
";
JQuery part:
<script type="text/javascript">
$(document).ready(function() {
$("#dialog").dialog({
autoOpen: false,
modal: true
});
});
$("#DeleteButton").click(function(e) {
e.preventDefault();
currentForm = $(this).closest('form');
$("#dialog").dialog({
dialogClass: "no-close",
buttons : {
"yes" : function() {
currentForm.submit();
},
"no" : function() {
$(this).dialog("close");
}
}
});
$("#dialog").dialog("open");
});
</script>
The problem is this code is not working. If I don't add jquery part the code is perfectly working but after adding jquery part when I click submit button the jquery dialog appears but after clicking yes button the form will be submitted without deleting selected item.