I have a function in my code that gets a value for variable appID, like so:
$.post("/jqf/updfam_processajax.php", {ADULT: answer1, CHILD: answer2}, function (data77) {
var obj77 = $.parseJSON(data77);
appID = obj77[0].idlinksAppID;
});
I'd like to use the value of that variable later on in my code in a seperate function, like so:
$.post("/jqf/updfam_processajax.php", {PID3a: appID}, function (data20) {
var obj20 = $.parseJSON(data20);
$(obj20).each(function (index) {
$('#ParentHCACYrs').children("option[value=" + obj20[index].parenthcacyrsYear + "]").prop('selected', true);
});
});
I have defined the appID variable above the first function as blank, but when I console.log the value of the variable I get a good value inside the top function but I get 'undefined' when trying to use the value in the second function. I was under the impression this would work, but apparently not. I have reviewed info on this but can't seem to find the right information. Any help please?
EDIT
The code now reads as such:
$.post("/jqf/updfam_processajax.php", {ADULT: answer1, CHILD: answer2}, function (data77) {
var obj77 = $.parseJSON(data77);
appID = obj77[0].idlinksAppID;
$.post("/jqf/updfam_processajax.php", {PID3a: appID}, function (data20) {
var obj20 = $.parseJSON(data20);
$(obj20).each(function (index) {
$('#ParentHCACYrs').children("option[value=" + obj20[index].parenthcacyrsYear + "]").prop('selected', true);
});
});
$.post("/jqf/updfam_processajax.php", {PID4: appID}, function (data21) {
var obj21 = $.parseJSON(data21);
$(obj21).each(function (index) {
$('#ParentHCACLangs').children("option[value=" + obj21[index].parenthcaclangsLang + "]").prop('selected', true);
});
});
});
When I use Chrome developer tools, I don't see the 2 sub-posts going through...