I am generating an HTML table dynamically using JavaScript. One of the table's columns contains an onmouseover
event, and when the mouse cursor is over a particular cell, I wish to display cell specific information.
In my case, I wish to display the value of nPos
via an alert()
call as it was during the table construction.
Simplified example of my table creation:
for (var iLoop = 0 ; iLoop < nHitsPerPage ; iLoop++) {
var nPos = (nCurrentPageParam * SearchResults.nMaximumHitsPage) + iLoop;
//...
var cellInfo = tableResultsRow.insertCell(6);
//...
cellInfo.className = "noWrapCell";
cellInfo.innerHTML = "?";
cellInfo.style.cursor = "pointer";
// The line below is important - I need to store nPos value during the table consturction
cellInfo.onmouseover = function(){alert("nPos = " + nPos)};
cellInfo.onmousemove = function(){FileResort.LightboxShortInfo.update(event)};
cellInfo.onmouseout = function(){FileResort.LightboxShortInfo.hide(event)};
}
As you can see from the example above, I iteratively created a table within my for()
loop. I want to store the value of the nPos
within every row (record) which is different for each row (record).
My problem is that once I mouseover that particular cell, I get the same nPos
value for every row (record), and that nPos
is the current value of nPos
at the particular application state.
I cannot find a way to record the nPos
value as it was during the for()
execution, which is important for me in identifying what record is stored in the particular row.
Is there a way to capture, or store the value of nPos
for every row (record) during the table's initial construction?