我有一个包含按钮的表格行:
<form id='studentAddForm'>
<table id='removetbl'>
<tr>
<td><button id='submitstudents'>Submit Students</button></td>
</table>
</form>
单击按钮时,它会显示一个确认框,但是当我单击Cancel
确认框中的按钮时,它仍然要加载页面吗?我的页面没有错误
下面是显示点击事件、确认和提交表单的 jquery 代码:
function submitform() {
$.ajax({
type: "POST",
url: "updatestudentsession.php",
data: {
sessionid: $('#currentid').val(),
students: $('#addtextarea').val()
},
dataType:'json', //get response as json
success: function(result) {
if(result.errorflag) {
//do your stuff on getting error message
var newHtml="<span style='color: red'>"+result.msg+"</span>";
$("#targetdiv").html(newHtml); //i am displaying the error msg here
} else {
//you got success message
var newHtml="<span style='color: green'>"+result.msg+"</span>";
$("#targetdiv").html(newHtml);
$('#targetdiv').show();
}
}
});
}
function showConfirm() {
var examInput = document.getElementById('newAssessment').value;
if (editvalidation()) {
var confirmMsg=confirm("Are you sure you want to add your selected Students to this Assessment:" + "\n" + "Exam: " + examInput);
if (confirmMsg==true) {
submitform();
}
}
}
$('body').on('click', '#submitstudents', showConfirm);
更新:
我不知道下面的信息是否会进一步帮助您,但下面显示了页面中的所有表格:
表格 1:
$assessmentform = "<div id='lt-container'>
<form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post' id='assessmentForm'>
<p id='warnings'>{$pHTML}</p>
{$outputmodule}
<p><strong>Assessments:</strong> {$sessionHTML} </p>
</form>";
echo $assessmentform;
表格 2:
$editsession = "
<form id='updateForm'>
<p><strong>Assessment Chosen:</strong></p>
<table>
<tr>
<th></th>
<td><input type='hidden' id='currentId' name='Idcurrent' readonly='readonly' value='' /> </td>
</tr>
<tr>
<th>Assessment:</th>
<td><input type='text' id='currentAssessment' name='Assessmentcurrent' readonly='readonly' value='' /> </td>
</tr>
</table>
<div id='currentAlert'></div>
";
echo $editsession;
表格 3:
$studentexist="
<form id='studentExistForm'>
<p><strong>Current Students in Chosen Assessment:</strong></p>
<p>{$studentSELECT}</p>
</form>
</div>";
echo $studentexist;
表格 4:
$studentremain="<div id='rt-container'>
<form id='studentRemainForm'>
<p>{$remainSELECT}</p>
<table id='addtbl'>
<tr>
<td><button type='button' id='addbtn'>Add</button></td>
<td><button type='button' id='addall'>Select All</button></td>
<td><button type='button' id='adddeselect'>Deselect All</button></td>
</table>
</form>";
echo $studentremain;
表格 5:
$studentadd="
<form id='studentAddForm'>
<p>{$addSELECT}</p>
<table id='removetbl'>
<tr>
<td><button id='submitstudents'>Submit Students</button></td>
</table>
</form>
</div>";
echo $studentadd;