Hi I am a beginner programmer and I need to run several javascript functions in an order on a page; getcampaignID(), search1(), searchresult(), search2(), searchresult(). I need to retrieve the campaign ID first to send it over to search1(), get the result, then running search2() to get its result next.
I have successfully ran [search1() + searchresult()] before  [search2() + searchresult()] by executing the search1() after the </body> tag and adding a setTimeout in searchresult(). However, I am unable to run getcampaignID first without breaking search1() and search2() 
My code looks like this: home.html
<script>
getcampaignID() {
    //...make AJAX call to get campaignID
    campaignID = xmlhttp.responseText.trim();
}
getcampaignID(); //run function
searchresult() {
        //...retrieves search results
        //...appends to html div
        setTimeout(function () {
            if (counter == 0) {
                counter = 1;
                search2();
            } else {
                clearTimeout(timer);
            }
        }, 500);
    } //end of searchresults
search1() {
    //...search1 parameters 
    //url=?camid = campaignID
    //campaignID unidentified
}
search2() {
    //...search2 parameters 
    //url=?camid = campaignID
    //campaignID unidentified
}
</script>
<body>
<div id= results1>...</div>
<div id= results2>...</div>
</body>
<script>
         search1();
</script>
Things I have tried:
        getcampaignID() {
            //... all the codes mentioned
            search1() {
                alert("search1 working");
            }
            search2() {
                alert("search2 working");
            }
        }
        search1();
Problem: search1() won't run, no alerts fired.
getcampaignID() {
    var campaignid = "A";
    big(campaignid);
}
big
function (campaignid) {
    //..all codes
    search1() {
        alert("search1 working");
    }
    search2() {
        alert("search2 working");
    }
    search1();
}
search1();
Problem: search1() won't run, no alerts fired.
Summary:
I am looking for a way to add campaignID value in search1(); before search1 runs 
 
     
     
     
    