assigning a function with variables to an element, how to do it?

Giganews Newsgroups
Subject: assigning a function with variables to an element, how to do it?
Posted by:  windandwaves (nfranck…@gmail.com)
Date: Thu, 12 Jul 2007

Hi Folk

How can I rewrite the function below so that it works.  Problem is I
can't get the functions assigned properly to the al element.

What am I doing wrong?

var buttonNames = new Array("", "plus", "minus","left", "up",
"down","right", "reset" );

var buttonFunction = new Array("", "zoom", "zoom", "scroll",
"scroll","scroll", "scroll", "");

var buttonLowSpeed = new Array(99, 3, 3, -3, -3, 3, 3, 99);

var buttonHighSpeed = new Array(99, 9, 9, -9, -9, 9, 9, 99);

var buttonDirection = new Array(99, 1, -1, 0, 1, 1, 0, 99 );

function init() {

for(var i = 1; i < 8; i++ ) {

  var al = document.getElementById("a" + buttonNames[i]);

  al.onclick = function () {return false;}

  al.onmousedown = function(){buttonFunction[i] + "(" +
buttonHighSpeed[i] + ", " + buttonDirection[i] + ",0," + i + ");"}

  al.onmouseover = function() {buttonFunction[i]
( buttonLowSpeed[i],buttonDirection[i],0,0);}

  al.onmouseup = function() {"stop(" + i + ");";}

  al.onmouseout = function () {"stop(" + i + ");";}

}
}

function zoom(A,B, C, D){
....
}
function scroll (A, B, C, D) {
....
}

Replies