Changing Hidden Field Values in JQuery Not Getting Changed :(

Changing Hidden Field Values in JQuery Not Getting Changed :(

I'm missing something, I'm afraid it's probably something very basic...

I have a hidden field in my html:

    1.     <asp:HiddenField ID="exportMedia" Value="html" runat="server" />
    I have two buttons that call a javascript and pass in which button was clicked:

    Print Button:
    1.         <div class="btn-group hidden-xs col-md-1 col-md-offset-0">
    2.             <button id="prt" class="btn btn-danger btn-sm" type="button" onclick="isMultiPageExport('print');">
    3.                 <span class="glyphicon glyphicon-print" style="color: white;"  aria-hidden="true"></span> Print
    4.             </button>
    5.         </div>
    PDF Button:
    1.         <div class="btn-group hidden-xs col-md-1 col-md-offset-0">
    2.             <button id="pdf" class="btn btn-danger btn-sm" type="button" onclick="isMultiPageExport('pdf');">
    3.                 <span class="glyphicon glyphicon-download" style="color: white;"  aria-hidden="true"></span> PDF
    4.             </button>
    5.         </div>
    The function that is being called:
    1.         function isMultiPageExport(exportType) {
    2.             document.getElementById("exportMedia").value = exportType;

    3.             $.ajax({
    4.                 type: "post",
    5.                 contentType: "application/json; charset=UTF-8",
    6.                 url: "../WebServices/myLocations.asmx/isMultiPageExport",
    7.                 data: "{ 'pageID' : '29' }",
    8.                 dataType: "json",
    9.                 success: function (response) {
    10.                     if (response.d == "1") {    //An area is being looked at, give the option to print indvidual schools within area
    11.                         $('#exportModal').modal();
    12.                     }
    13.                     else {  //Only printing the current html on the screen 
    14.                         if (exportType == "print") {
    15.                             printElement(document.getElementById("expEOC_pageOne"));
    16.                         }
    17.                         else {
    18.                             document.getElementById("exportStatus").value = 'html';
    19.                         }
    20.                     }
    21.                 }
    22.             })
    23.         }
    So up to this point, everything works as expected.  The exportMedia hiddenField is changed, and the multiPageExport function goes off and gathers data and prepares for the next action.  At some point, the page is getting refreshed, and the first thing my javascript does is flash up an alert to show me what the exportMedia hiddenField value is, which is at this point either print or pdf, what I am expecting.  Next my javascript checks and makes sure all the images on the page are getting fully loaded before continuing.  Once it sees they have, it checks the value of exportMedia, and if it's not equal to 'html' (at this point it's not) it either prints or export the data.  The final thing it does is change the exportMedia value back to html, it's default value.  The alert confirms that this is the case.

    1.         //Used to make sure all of the images have fully loaded
    2.         loadImages = 0;
    3.         timesChecked = 0;
    4.         checkInterval = 500;
    5.         maxLoadTime = 10000;    //in milliseconds

    6.         window.addEventListener('load', function () {
    7.             for (var i = 0; i < document.getElementsByName('img').length; i++) {
    8.                 document.getElementsByName('img')[i].onload = function () {
    9.                     loadImages++;
    10.                 }
    11.             }

    12.             intervalID = setInterval("checkImageLoads()", checkInterval);
    13.         })

    14.         //After the page has fully rendered, this function is called to see if all the chart images have finished loading
    15.         //and if so, copy the fully rendered html page into the hidden field for export
    16.         function checkImageLoads() {
    17.             timesChecked++;
    18.             if (loadImages >= document.getElementsByName('img').length || timesChecked * checkInterval >= maxLoadTime) {
    19.                 clearInterval(intervalID);

    20.                 if (document.getElementById("exportMedia").value != "html") {
    21.                     if (document.getElementById("exportMedia").value == 'print') {
    22.                         printElement(document.getElementById("export_pdf"));
    23.                     }
    24.                     else if (document.getElementById("exportMedia").value == 'pdf') {  //pdf
    25.                         exportSource.value = document.getElementById("export_pdf").innerHTML;
    26.                         $('#exportFinally').modal();
    27.                     }

    28.                     document.getElementById("exportMedia").value = "html";
    29.                     alert(document.getElementById("exportMedia").value);
    30.                 }
    31.             }
    32.         }
    At this point, if you hit the browser refresh button, when it hits the initial javascript alert, the exportMedia value has been flipped back to either print or pdf.  This is making no sense to me.  I've been trying to figure this out all day, and I'm completely at my wits end.  Any help or suggestions would be greatly, greatly appreciated.