aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Using getElementbyId to set event handlers globally Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Using getElementbyId to set event handlers globally" Watch "Using getElementbyId to set event handlers globally" New topic
Author

Using getElementbyId to set event handlers globally

John Walbaum
Greenhorn

Joined: Dec 19, 2005
Posts: 7
Anyone know how to get the value of currentImg in the following script assigned as the loop is made. Right now, it's assigning the value at the end of the loop. But I want to establish a permanent value for each "Img" in the array that can be passed to the function newWindow, so when the user clicks on a particular image, a new page with additional information opens up.


var currentImg = -1;
function changeImages(dir){
if(dir==-1) {
currentImg-=numDisplay*2;
if(currentImg<0 && dir)currentImg = theImg.length + currentImg;
}
for(i=0;i<numDisplay;i++){
currentImg++;
if(currentImg >= theImg.length)currentImg=0;
document.getElementById("Img" + i).src = theImg[currentImg][0];
document.getElementById("Img" + i).alt = theImg[currentImg][1];
document.getElementById("Img_text" + i).innerHTML = theImg[currentImg][1];
document.getElementById("Img" + i).onklick = function(){newWindow('currentImg')}
}
}
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
I did not forget about you, I am swamped with work...

Why the single quotes around currentimage in the function declaration??

Eric
John Walbaum
Greenhorn

Joined: Dec 19, 2005
Posts: 7
Sorry. I knew you were busy so I thought I would give the peanut gallery a try.

Re your question: The text you suggested did not work. I found a new syntax <a href="http://www.codingforums.com/archive/index.php?t-5958.html">here</a>, a forum where others were having the same problem. The brackets and single quotes were a workaround.

It seemed to clear up the problem I was having in that the onklick event handler now works. The trouble is that the onklick function value is wrong. It's kind of like a loop that runs to six and instead of assigning i(1) = 1, i(2) = 2, etc., it assigns i(1) = 6, i(2) = 6, etc. I can't figure out the problem, but guess it has to do with the variable type.
John Walbaum
Greenhorn

Joined: Dec 19, 2005
Posts: 7
Sorry. I knew you were busy so I thought I would give the peanut gallery a try.

Re your question: The text you suggested did not work. I found a new syntax <a href="http://www.codingforums.com/archive/index.php?t-5958.html">here</a>, a forum where others were having the same problem. The brackets and single quotes were a workaround.

It seemed to clear up the problem I was having in that the onklick event handler now works. The trouble is that the onklick function value is wrong. It's kind of like a loop that runs to six and instead of assigning i(1) = 1, i(2) = 2, etc., it assigns i(1) = 6, i(2) = 6, etc. I can't figure out the problem, but guess it has to do with the variable type.
 
Don't get me started about those stupid light bulbs.
 
subject: Using getElementbyId to set event handlers globally