I am struggling to figure out how to pass a <div id> to another javascript. For example, at the start of my page I have the following script which creates a div id tag that allows me to dynamically select and change content of the page.
$(document).ready(function() {
$("select").change(function() {
var subFolder = $(this).val();
$('#folderName').text(subFolder);
$('#stats').attr('src', '/hardware/' + subFolder + '/stats/usage.txt');
$('#hostInfo').attr('src', '/hardware/' + subFolder + '/stats/host.txt');
$('#folderContent').show();
});
$.ajax({
url: 'getFolders.php',
type: 'GET',
dataType: 'json',
success: function(json) {
var $selectBox = $('#folderList');
$.each(json, function(i, value) {
$selectBox.append($('<option>').text(value).attr('value', value));
});
$selectBox.change();
}
});
});
This allows me to do the following - this creates a selector that a particular folder can be selected.
<div class="hidden-print">
<select id='folderList'></select>
</div>
When the folder list is selected above it allows me to change content like the items below:
like the above to another java script.
$(document).ready(function() {
$('#example3').DataTable( {
"processing": true,
"ajax": {
"url" : "../../reports/drives.txt",
"dataSrc" : ""
},
"columns": [
{ "data": "Hostname.Name" },
{ "data": "Name"}
]
} );
} );
When i select a folder above from the selector i would like the folder under the URL under the AJAX to be modified along with it to update it.
UPDATE
After looking at this a bit further I don't think my explanation fit very well.
$(document).ready(function() {
$("select").change(function() {
var subFolder = $(this).val();
$('#folderName').text(subFolder);
$('#folderLogo').attr('src', '/server/' + subFolder + '/Logo/hardware.png');
$('#folderContent').show();
});
$.ajax({
url: 'getFolders.php',
type: 'GET',
dataType: 'json',
success: function(json) {
var $selectBox = $('#folderList');
$.each(json, function(i, value) {
$selectBox.append($('<option>').text(value).attr('value', value));
});
$selectBox.change();
}
});
});
var thisId = $('folderList').attr('id');
I want to take this variable which should be a single folder and use it on a script like the one below.
var subFolder = $(this).val();
$('#folderName').text(subFolder);
$('#folderLogo').attr('src', '/server/' + subFolder + '/Logo/hardware.png');
I would like to take the "subfolder" and use it something like the following:
$(document).ready(function() {
$('#example3').DataTable( {
"processing": true,
"ajax": {
"url" : "/server/" + subfolder + "/Stats/Map.txt",
"dataSrc" : ""
},
"columns": [
{ "data": "Hostname.Name" },
{ "data": "Name"}
]
} );
} );
I tried to get the method below to get a div id conversion and it doesn't have any data when i try it that way. I should have stated i want to use the variable in the sub folder in the script above... I tried a window.variable name i have tried the global variable and still nothing seems to be working correctly. My guess is that the way the variable is being processed is not carrying over.