Eric on 28 Jan 2009 20:50:26 -0800

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[PLUG] OT: Javascript question

Not sure where to go with this... it's not really liunx although I'm 
developing it on a Linux system :-)  

I'm writing some client-side Javascript to allow the user to select 
between an undetermined number of choices that I build in a list 
dynamically.  There are two loops.  First is a loop that creates the 
links and that works fine.  The second is a loop that is supposed to 
create and bind an anonymous function to the click event of each of the 
links created in the first loop.  (it has to be done in two loops 
because you cannot bind event handlers to DOM elements that don't exist 

Unfortunately, I get the last function for all links;  Here is the loop:

            for ( var loop2 = 0; loop2 < count ; loop2++ ) {
                var vehID = 
doc.getElementsByTagName("id")[loop2].childNodes[0].nodeValue ;
                var loadURL = "/index.php/ajaxserver/vehiclebyid/" + 
vehID + "/" ;
                var tag = "#choice" + loop2 ;
                alert("loadURL: " + loadURL + "\nTag: " + tag) ;
                $(tag).bind("click",function() {
                    loadXMLDoc(loadURL) ;
                    $("#dialogpane").html("") ;
                }) ;

Any JavaScript expertise out there?


#  Eric Lucas
#                "Oh, I have slipped the surly bond of earth
#                 And danced the skies on laughter-silvered wings...
#                                        -- John Gillespie Magee Jr

Philadelphia Linux Users Group         --
Announcements -
General Discussion  --