I wanted to pass two values to a click function and use the values to load a file in to a specific DIV. The file to load is called ‘displayTwo.txt' from the 'partialContent' directory and the DIV that the contents of the file will be place in has the ID of ‘mark03’. I do this by placing the following line in my menu:
<li role="presentation" id="param" data-options="{File: 'partialContent/displayTwo.txt', Id: '#mark03'}"><a href="#">ShowLink</a></li>
Next I have this jQuery function to perform the operation with some debug code.
$('#param').click(function () {
localData = $("#param").data('options');
console.log("localData = " + localData + '\n');
var file = localData.File;
console.log("file = " + file + "\n");
var id = localData.Id;
console.log("Id = " + id + "\n");
event.preventDefault();
$(id).load(file);
});
});
Well this does not work and at the end of this note is the output. I am able to grab the data in the variable “localData” but I am not able to collect the two parts File and Id to place them into the jQuery load function. I have tried various syntax form such as localData.Id or localData[Id] but neither works.
The following is the debug output. Note that I can see the values in the initial console.log of localData.
localJS.js:17 localData = {File: 'partialContent/displayTwo.txt', Id: '#mark03'}
localJS.js:19 file = undefined
localJS.js:21 Id = undefined
jquery-3.2.0.min.js:4 Uncaught TypeError: Cannot read property 'indexOf' of undefined
at r.fn.init.r.fn.load (jquery-3.2.0.min.js:4)
at HTMLLIElement.<anonymous> (localJS.js:23)
at HTMLLIElement.dispatch (jquery-3.2.0.min.js:3)
at HTMLLIElement.q.handle (jquery-3.2.0.min.js:3)
r.fn.load @ jquery-3.2.0.min.js:4
(anonymous) @ localJS.js:23
dispatch @ jquery-3.2.0.min.js:3
q.handle @ jquery-3.2.0.min.js:3