我正在努力使用提交按钮,单击该按钮时没有任何反应。我相信问题是没有editvalidation()
被触发,但我不确定。如果是这种情况,如何触发?我希望验证显示在它自己的提交按钮上方。我的问题只是如何让提交按钮做某事?
我没有收到任何错误:
代码:
<script type="text/javascript">
function editvalidation()
{
if ($("#coursesDrop").val()==""){
$("#courseAlert").html("Please Select a Course from the Course Drop Down Menu");
}
if ($("#coursesDrop").val()!="" && $("#courseadd").children().length==0){
$("#courseAlert").html("You have not Selected any Students you wish to Add into Course");
}
if ($("#coursesDrop").val()!="" && $("#courseadd").children().length!=0){
return true;
}
return false;
}
</script>
<div id='lt-container'>
<form action='addstudentcourse.php' method='post' id='courseForm'>
<p id='warnings'></p>
<p><strong>Courses:</strong> <select name="course" id="coursesDrop">
<option value="">Please Select</option>
<option value='19'>BIO234 - Biology</option>
<option value='1'>INFO101 - Bsc Information Communication Technology</option>
<option value='2'>INFO102 - Bsc Computing</option>
</select> </p>
</form>
<form id='updateForm'>
<p><strong>Course Chosen:</strong></p>
<table>
<tr>
<th></th>
<td><input type='hidden' id='currentCourseId' name='CourseIdcurrent' value='' /> </td>
</tr>
<tr>
<th>Course ID:</th>
<td><input type='text' id='currentCourse' name='Coursecurrent' readonly='readonly' value='' /> </td>
</tr>
<tr>
<th>Course Name:</th>
<td><input type='text' id='currentCourseName' name='CourseNamecurrent' readonly='readonly' value='' /> </td>
</tr>
<tr>
<th>Duration (Years):</th>
<td><input type='text' id='currentDuration' name='Durationcurrent' readonly='readonly' value=''/> </td>
</tr>
</table>
</form>
<form id='studentExistForm'>
<p><strong>Current Students in Chosen Course:</strong></p>
<p><select name="studenttextarea" id="studentselect" size="10"></select></p>
</form>
</div>
<div id='rt-container'>
<form id='studentRemainForm'>
<p><strong>Available Students to Enrol:</strong></p>
<p><select multiple="multiple" name="remaintextarea" id="studentremain" size="10"></select></p>
<table id='addtbl'>
<tr>
</table>
</form>
<form id='studentAddForm'>
<p><strong>Students to Add to Course:</strong></p>
<p><select multiple="multiple" name="addtextarea" id="studentadd" size="10"></select></p>
<table id='removetbl'>
<tr>
</table>
<div id='studentAlert'></div>
</form>
<p><button id='submitstudents'>Submit Students</button></p>
</div>
<script type="text/javascript">
function showConfirm(){
var courseNoInput = document.getElementById('currentCourse').value;
var courseNameInput = document.getElementById('currentCourseName').value;
if (editvalidation()) {
var confirmMsg=confirm("Are you sure you want to add your selected Students to this Course:" + "\n" + "Course: " + courseNoInput + " - " + courseNameInput);
if (confirmMsg==true)
{
submitform();
}
}
}
$('body').on('click', '#submitstudents', showConfirm);
</script>