[thelist] for loop, array and mouseover teazer

Chris Price chris.price at choctaw.co.uk
Thu Sep 6 14:36:37 CDT 2007


I have the following code:

<snip>

window.onload = initElement

function initElement() {
    var ball_object_array, ball_id_array, ballPark, count
   
    ball_object_array = new Array(7)
   
    ball_id_array = new Array 
('ball_image','ball1','ball2','ball3','ball4','ball5','ball6')
   
    ballPark = document.getElementById(ball_id_array[0])
   
    for (count=1;count<=6;count++) {
        ball_object_array[count] = 
document.getElementById(ball_id_array[count])
        ball_object_array[count].onmouseout = function() { 
restoreBall(ballPark); return false }
        }
       
    ball_object_array[1].onmouseover = function() { 
changeBall(ball_id_array[1],ballPark); return false }
    ball_object_array[2].onmouseover = function() { 
changeBall(ball_id_array[2],ballPark); return false }
    ball_object_array[3].onmouseover = function() { 
changeBall(ball_id_array[3],ballPark); return false }
    ball_object_array[4].onmouseover = function() { 
changeBall(ball_id_array[4],ballPark); return false }
    ball_object_array[5].onmouseover = function() { 
changeBall(ball_id_array[5],ballPark); return false }
    ball_object_array[6].onmouseover = function() { 
changeBall(ball_id_array[6],ballPark); return false }
       
    }
   
function changeBall(myBall,masterBall) {
    masterBall.src = 'sixball/' + myBall + '.jpg'
    }
   
function restoreBall(masterBall) {
    masterBall.src = 'sixball/ball0.jpg'
    }

</snip>

The ball_id's represent absolutely positioned divs.

The above code works fine but I want to include the onMouseOver's in the 
for loop. However if I have: ball_object_array[count].onmouseover = 
function() { changeBall(ball_id_array[count],ballPark); return false } 
count gets returned as 7 every time.

I can't work out what I'm missing here.

Kind Regards
-- 
Chris Price

Choctaw

chris.price at choctaw.co.uk
http://www.choctaw.co.uk

Tel. 01524 825 245
Mob. 0777 451 4488

Beauty is in the Eye of the Beholder
while Excellence is in the Hand of the Professional

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-+- Sent on behalf of Choctaw Media Ltd -+-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Choctaw Media Limited is a company
registered in England and Wales
with company number 04627649

Registered Office:
Lonsdale Partners,
Priory Close,
St Mary's Gate,
Lancaster LA1 1XB
United Kingdom





More information about the thelist mailing list