| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
knocking heads
Join Date: Jul 2003
Location: London, UK
Posts: 1,914
|
javascript variables
i have the following snippet of javascript: Code:
That code happens within a loop, and sub_menu_id has a different value through each iteration of the loop. For example, if it loops 4 times, then there will be 4 onclick functions and sub_menu_id would change for each one. This should happen in theory, but instead, whichever item you click on, sub_menu_id takes the value of its last value in the loop. (4 in this example) My question is, how do I make the function toggleSubMenu take the value of sub_menu_id at the time the on click function is created (i.e while looping) rather than taking the value of sub_menu_id when it is actually clicked. |
|
|
|
|
|
#2 (permalink) |
|
vague™
Join Date: Mar 2004
Location: Glasgow
Posts: 5,512
|
that looks fairly similar to something you come across in actionscript try setting the sub_menu_id property on the object itself liChilds[x].sub_menu_id = sub_menu_id; liChilds[x].onclick = function() { toggleSubMenu(this.sub_menu_id, false); return false; } |
|
![]() |