I have searched this online but I am stuck. I am calling a JavaScript function button click. It does not work unless I wrap it in $(document).ready(function() {}). However, I need to run the function not just after page load, but right after button click.
HTML Button :
<a href="/Spend/Job" onclick="return getisModified()" class="btn btn-default">Config </a>
JavaScript :
var isModified;
function getisModified() {
$.get("/Spend/Job/IsModified", function (data, status) {
if (status === "success" && data && data.length > 0) {
var dataObj = JSON.parse(data);
isModified = dataObj.IsModifiedAny;
}
});
if (isModified == true) { //if there are any modified rows
var response = confirm("You have made changes without running Config. Continue anyway?")
if (response) //user clicks OK
{
return true
} else { //user clicks cancel
return false
}
}
}
The code works when i run it in the console. But not when it is called after button click.