Change Path javascript

HTML

<script src="https://code.jquery.com/jquery-1.12.1.min.js"></script>
<div class="hidden-print">
    <select id='folderList'>
      <option value="default">Select a Folder</option>
      <option value="sampleFolder">SampleFolder</option>
    </select>
</div>

<!-- When you select a new folder from above it will change the content on the rest of the page. --> 
			<div class="text-center center-block" style="margin: 0 auto;">
				<div id='folderContent' style='display: none;'>
					<img src='' style='max-height: 150px;' width="400" id='folderLogo'>
    			</div>
			</div>
<!-- ABOVE CODE: When you change the folder list it then changes the folderLogo based on the div ID --> 
      <table id="example3" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
				<th>Hostname</th>
				<th>Datastore Name</th>
            </tr>
        </thead>
    </table>
<!-- ABOVE CODE: Again as the folder is selected above it will change the dat in the datatable. -->

JavaScript

var subFolder = '';
      $(document).ready(function() {
          $("select").change(function() {
              subFolder = $(this).val();
              $('#folderName').text(subFolder);
              $('#folderLogo').attr('src', '/hardware/' + subFolder + '/Logo/manufacture.png');
              $('#hdstats').attr('src', '/hardware/' + subFolder + '/stats/hdstats.csv');
              $('#folderContent').show(); 
          });
          
          // Toook out the AJAX call and provided a sample JSON for the purposes of the example. The AJAX being in a function still will allow it access to other variables
          var sampleJSON = {
          		name: 'anotherFolder'
          }
          var $selectBox = $('#folderList');
        	$.each(sampleJSON, function(i, value) { 
          	$selectBox.append($('<option>').text(value).attr('value', value));
        	});
        	$selectBox.change();
		  
      });
/*
With the above code it populates the folder drop down - getFolders.php goes and gets list of the folders and allows you to select a different one 
*/
 
/*
The below code is what i need to initialize datatables.  Ideally the subFolder above needs to carry over.   
*/

$(document).ready(function() {
    $('#example3').DataTable( {

	    "processing": true,
        "ajax": {
        	"url" : "/hardware/" + subFolder + "/stats/hdstats.txt",
        	"dataSrc" : ""
        },	
        "columns": [
            { "data": "Hostname.Name" },
            { "data": "Name"}
        ]
    } );
} );
/* I could see adding this code below within the main script that creates the folder list but it errors out and pisses datatables off doing that.  

  $('#example3').DataTable({
              "processing": true,
                  "ajax": {
                  "url" : "/customers/" +subFolder + "/SANStats/DatastoreMap.txt",
                  "dataSrc" : ""
                  },
                  "columns": [
                      { "data": "Hostname.Name"...