multiple selectors with similar name.

multiple selectors with similar name.

Hi,

Wasnt sure how to search for the answer so decided to just ask.

OK. I have a page that is created by php using data from a database. In this data I would like to include the ability to load more info from the database. This is how the php code looks at present...

$mainContent.="<a name=\"$mix[id]\"></a>\n";
$mainContent.="<h1>$mix[name]</h1>\n";
$mainContent.="<div id=\"tracklist_$mix[id]\"><a href=\"#\" onclick=\"getTracklist($mix[id]); return(false);\">Click here for tracklist</a></div>\n";


and the javascript
function getHTTPObject(){
   if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) return new XMLHttpRequest();
   else {
      alert("Your browser does not support AJAX.");
      return null;
   }
}

function getTracklist(MIXID){
   httpObject = getHTTPObject();
   if (httpObject != null) {
      httpObject.open("GET", "/getTracklist.php?mix=" + MIXID, true);
      httpObject.send(null);
      httpObject.onreadystatechange = setOutput(MIXID);
   }
}

function setOutput(MIXID){
   alert('Getting tracklist for mix ' + MIXID);
   if(httpObject.readyState == 4){
      var divid = 'tracklist_' + MIXID;
      document.getElementById(divid).innerHTML = httpObject.responseText;
   }
}

var httpObject = null;


So, each mix has an element for the tracklist to go into (tracklist_ N) which contains the link to get the tracklist.

Any idea what the best way to get this to work would be.

At the moment I am using a plain XMLHttpRequest, but for some reason it wont work unless there is an alert in the line before the code to fill in the div's innerHTML. No idea why, but thats the only way it will work