I'm attempting display a DIV when clicking on a list item. This works, but only for the first list item. I realized that this was due to the ID not being unique so I made the IDs unique. My question is how do I pass this unique ID from each list item to the relevant javascript function so that it displays the DIV when clicked?
Here's the javascript:
The HTML:
Here's the javascript:
Code:
// Create XmlHttp object.
function createXHR()
{
try { return new XMLHttpRequest(); } catch(e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
alert("XMLHttpRequest not supported");
return null;
}
function sendRequest()
{
var xhr = createXHR(); // cross browser XHR creation
if (xhr) // if created run request
{
xhr.open("GET","moreContent.php",true);
xhr.onreadystatechange = function(){handleResponse(xhr);};
xhr.send(null);
}
}
function handleResponse(xhr)
{
if (xhr.readyState == 4 && xhr.status == 200)
{
var responseOutput = document.getElementById("responseOutput");
responseOutput.innerHTML = xhr.responseText;
responseOutput.style.display = "";
}
}
window.onload = function ()
{
document.getElementById(uniqueId).onclick = sendRequest;
}
Code:
foreach($rs as $k => $row)
{
if (checkFlag($row[flags], TEST_FAILED))
{
echo "<li id=\"failContent\">";
}
else
{
echo "<li id=\"$row[id]\">";
}
echo "Summary data";
echo "<div id=\"responseOutput\"></div>";
echo "</li>";
echo "\n";
}
Comment