$(document).ready(function() {
$("form").submit(function(e) {
if (!checkStockOfProduct())
{
e.preventDefault();
return false;
}
return true
});
});
<script src="~/Scripts/storeinputoutput.js"></script>
storeinputoutput.js file:
function checkStockOfProduct() {
var allowSubmitForm = true;
$("table#StoreItemdatatable > tbody > tr").each(function () {
.
.
.
var storeId = $('#StoreID').val();
var stock = null;
var URL = '/aaa/bbb'
$.ajax({
async: false,
url: URL,
contentType: 'application/x-www-form-urlencoded',
dataType: 'json',
data: {
productNServiceID: productNServiceID,
storeID: storeId
},
type: 'POST',
success: function (data) {
stock = data.Stock;
}
, error: function (jqXHR, exception) {
}
});
if (...) {
allowSubmitForm = false;
}
return allowSubmitForm;
});
}
In form submit , I called the function and I wouldn't do the submit operation if function return false. But the value of the xx variable is always undefined.
Please advise
Checked using Alert. variable "allowSubmitForm" in function "checkStockOfProduct" in the last line has value and not "undefined" But in Submit it is undefined