Hi, It's not that it's conflicting with Ajax, it's that you're using a "for in" loop in an incorrect (but common) way:
> for ( var i in responseArr ) The JavaScript "for in" loop iterates over properties of an object, not elements of an array. Array elements are also properties of the array object, and as long as the array has no other enumerable properties (which is usually the case), you can get away with using "for in" in this way. But as soon as you assign custom properties to an array, "for in" loops expecting to see only array elements break because (again) that's not what "for in" does. This shows up when you include Prototype (used by script.aculo.us) in your page because Prototype adds a bunch of useful functions to arrays, and those show up as enumerable properties. More here, along with how to loop arrays in other more reliable ways: http://proto-scripty.wikidot.com/prototype:tip-looping-through-arrays HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Feb 17, 9:16 pm, "yoteecoy...@gmail.com" <yoteecoy...@gmail.com> wrote: > I am encountering odd behavior when I include scriptaculous libraries > on a page where I have done custom HTTP requests (AJAX). > > Please view this > screenshot:https://mywebspace.wisc.edu/ahoffmann/pub/autocompleter_bug.jpg > > When the user selects a Project, I generate a list of teams in a drop > down for that project to select from. If I include scriptaculous > libraries on this page, bizarre code gets placed in the drop-down. If > I take out the libraries, it works correctly. > > The HTTP request I am doing is simple, and I am using a structure I > found at w3schools.com. The list of teams is returned as a delimited > file. The delimiter is ;; which may be the problem. Can someone look > at my Javascript and suggest an error that would cause it to conflict > with the scriptaculous libraries? > > Thank you very much! > > Coyote Hoffmann > University of Wisconsin > > ======= BEGIN JAVASCRIPT CODE ====== > > function getTeams() { > > var myXMLHTTP; > var project = document.getElementById("project").value; > > if ( project != "xxx" ) { > > // Enable user box > document.getElementById("user").disabled = false; > > // Set autocomplete box project number > auto_project = project; > > try { > // Firefox, Opera 8.0+, Safari > myXMLHTTP=new XMLHttpRequest(); > } catch (e) { > // Internet Explorer > try { > myXMLHTTP=new ActiveXObject("Msxml2.XMLHTTP"); > } catch (e) { > try { > myXMLHTTP=new ActiveXObject("Microsoft.XMLHTTP"); > } catch (e) { > return false; > } > } > } > > myXMLHTTP.onreadystatechange=function() { > if ( myXMLHTTP.readyState == 4 ) { > > document.getElementById("team").options.length = 0; > document.getElementById("team").options[0] = new Option > ( "- All Teams -", "*", true, true ); > > var response = new String( myXMLHTTP.responseText ); > alert(response); > var responseArr = new Array(); > responseArr = response.split( ";;" ); > > var j = 1; > for ( var i in responseArr ) { > if ( responseArr[i] != "" ) { > var teamStr = new String( responseArr[i] ); > var teamArr = teamStr.split( ";" ); > var teamId = teamArr[0]; > var teamName = teamArr[1]; > document.getElementById("team").options[j] = > new Option( teamName, teamId, false, false ); > } > j++; > } > > document.getElementById("team").disabled = false; > } > } > > myXMLHTTP.open("GET","ajax_teams_from_project.php?project=" + > project, true); > myXMLHTTP.send( null ); > > } else { > document.getElementById("team").disabled = true; > document.getElementById("team").options.length = 0; > document.getElementById("team").options[0] = new Option( "- > Select Team -", "xxx", true, true ); > > // Disable user box > document.getElementById("user").disabled = true; > document.getElementById("user").value = ""; > document.getElementById("user_id").value = ""; > auto_project = null; > } > > } > > ====== END JAVASCRIPT CODE ====== --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---