Old 20-03-2007, 10:24   #1 (permalink)
stealthcow
knocking heads
 
stealthcow's Avatar
 
Join Date: Jul 2003
Location: London, UK
Posts: 1,914
javascript variables

i have the following snippet of javascript:

Code:
liChilds[x].onclick = function(){ toggleSubMenu(sub_menu_id, false); return false; }

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.
  Reply With Quote
Old 20-03-2007, 11:51   #2 (permalink)
cam
vague™
 
cam's Avatar
 
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; }
__________________
  Reply With Quote
Old 20-03-2007, 12:21   #3 (permalink)
stealthcow
knocking heads
 
stealthcow's Avatar
 
Join Date: Jul 2003
Location: London, UK
Posts: 1,914
that works, cheers
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8