hi guys

i cant seem to get my head round a problem here. I am sure someone can
help.

I have included the hotkeys plugin. It all works fine. One adds a
hotkey by simply calling the function $.hotkeys.add(key, function); so
for example if $.hotkeys.add('1', levelClicked), the function
levelClicked is called when 1 is pressed.

However i want to restrict users to using a subset of the numeric keys
depending on the value of a variable and I want to do it on-the-fly.
SO if the variable is 5 i allow users to keypress 1,2,3,4 and 5, but
exclude any digits above this variable value.
and if 7 then 1,2,3,4,5,6,7, etc

I thought it would be simple using a for loop

var lastNum = 5; //say
for (i = 49; i <= (49+lastNum); i++)
{
 $.hotkeys.add(String.fromCharCode(i), function () {levelClicked(i)});
}

.
.
.

function levelClicked(i)
{
alert (i);
}

now it always alerts as whichever value lastNum was assigned to :
( irrespective of whether i click 1,2,3,4 or 5.
My first impression is that it was a scoping issue (and i think it
is) . i tried assigning i to auxiliary vars but the errant logic (on
my part :) ) persists

Can someone give me some insight pls and a solution?
thx in advance

Reply via email to