Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi guys,
i have a JS script file in Qlikview , i have written a code:
var td = _this.Data;
for(var rowIx = 0; rowIx < td.Rows.length; rowIx++) {
//set the current row to a variable
var row = td.Rows[rowIx];
var start=row[0].text;
var end= row[1].text
;document.getElementById(start).addEventListener(some function);
document.getElementById(start).addEventListener(some function);
}
the problem is the getElementByID is not retrieving any value , what i need is the value or ID need to be passed .
Kindly please suggest me any alternative for this
Thank,
Vivek
The document.getElementById function retrieves a DOM element with a given id. The content of the Data.Rows is not DOM elements but plain javascript object without representation in the document.
You have first to create a DOM element containing your extension data, add it to your extension element (which is this.Element in your function), and then add an event listener to it.
For example:
var td = _this.Data;
for(var rowIx = 0; rowIx < td.Rows.length; rowIx++) {
var row = td.Rows[rowIx];
var start = row[0].text;
var end = row[1].text;
// create a <div> element representing the data row
var start_element = document.createElement('div');
// set the content of the <div> to be the text of the first column of the row
start_element.innerHTML = start;
// add the div to the extension element
_this.Element.appendChild(start_element);
// listen to the 'click' event on the element
start_element.addEventListener('click', function() { alert('I was clicked!'); });
}
Note that you don't have to call document.getElementById since you already have a reference to the element (returned by createElement).