Reputation: 270
I have a button below:
<p><button id='submitstudents'>Submit Students</button></p>
What I want the button to do is to trigger the editvalidation()
function and if that is passed then proceed with the confirmation. I have the jquery code set up for the validation and for showing the confirmation if the validation has passed but how do I get the button to return the editvalidation()
whenc clicked on?
Below is relevant jquery code:
editvalidation():
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;
}
showConfirm():
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();
}
}
}
current even to check for click on button:
$('body').on('click', '#submitstudents', showConfirm);
Upvotes: 0
Views: 65
Reputation: 300
I've encountered this before. This code works perfect all the time:
$('#submitstudents').live('click', function(){
...do what ever you want...
});
Upvotes: 0
Reputation: 24276
Try this:
$('#submitstudents').click(function(){
if(editvalidation())
showConfirm();
});
Upvotes: 0
Reputation: 6416
Have you tried
$('#submitstudents').on('click', function(){ if(editvalidation()) showConfirm(); });
?
Upvotes: 1