我的表单使用普通的Javascript
提交正常但是当我尝试使用Jquery
时它不会
表格......
<form class="control_select" name="audit_delete_form" id="audit_delete_form"
method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select id="audit_id_select" name="audit_id_select">
<option value="">Please select</option>
<? while($row = mysqli_fetch_assoc($result)){
echo '<option value="'.$row['auditID'].'">'.$row['auditName'].'</option>';}?>
</select>
<input type="submit" name="audit_delete_submit" id="audit_delete_submit" value="" />
</form>
php ..
if(isset($_POST['audit_delete_submit'])){
$audit_id = $_POST['audit_id_select'];
$sql = "UPDATE audit SET auditComplete = 1, deleted = 1 WHERE auditID = '$audit_id'";
$result2 = mysqli_query($mysqli,$sql) or die(mysqli_error($mysqli));
}
jquery ......
$(document).ready(function(){
$("#audit_delete_submit").click(function(e){
e.preventDefault();
var x=document.forms["audit_delete_form"]["audit_id_select"].value;
if(x==null || x=="") {
$.msgbox("Please select an audit", {
type:"alert",
buttons: [
{type: "submit", value: "OK"}
]
});
}else{
$.msgbox("Are you sure you want to permanently delete this audit?", {
type: "confirm",
buttons : [
{type: "submit", value: "Yes"},
{type: "submit", value: "No"},
{type: "cancel", value: "Cancel"}
]
}, function(result){
if(result == "Yes"){
alert(result);
$("form#audit_delete_form").submit()
}
});
}
});
});
所有Jquery
除了实际提交外都有效,包括显示正确值的alert(result)
答案 0 :(得分:0)
这是一个奇怪的技巧,但是如果你在函数的末尾添加return false
,那么提交应该有效。我去过那里,修好了:)
}
return false;
});
});
答案 1 :(得分:0)
我不熟悉$ .msgbox lib,但是快速扫描API文档,看起来你应该把回调函数作为options对象的'success'参数:
$.msgbox("Are you sure you want to permanently delete this audit?", {
type: "confirm"
, buttons : [
{type: "submit", value: "Yes"},
{type: "submit", value: "No"},
{type: "cancel", value: "Cancel"}
]
, success: function(result) {
if(result == "Yes"){
alert(result);
$("form#audit_delete_form").submit()
}
}
});