I am trying to run two JavaScript functions, but the second function needs to wait for the first function to finish.
View:
<button id="DefinirEstab" class="btn btn-success btn-lg" data-toggle="modal" data-target="#myModal" onclick="saveContrato(); CountEstab()"> Define
</button>
First JavaScript function:
function saveContrato() {
$("#formContrato").ajaxSubmit({
type: "POST",
url: $("#formContrato").attr("action"),
clearForm: false,
success: function () {
$("#Serie").attr("disabled", true)
}
});
$("#DefinirEstab").attr("onclick", "CountEstab()");
}
Second JavaScript function (waits for the first one to finish):
function CountEstab() {
//Save data in the service table
var Serie = $("#Serie").val();
var NumDoc = $("#NumDoc").val();
$.getJSON("/Contrato/saveCabecalhoServicos", {
serie: Serie, numDoc: NumDoc, idForn: window.IdFornecedor, idFilial: e
});
} else {
alert("Missing mandatory data!!");
}
}