I'm trying to change the ID of a div via Ajax.
Because the ID has a dynamic value I added a class to the div.
My php code:
echo '<div id="pagemenu">
<ul id="tabpanel">';
$tel = 0;
while($totaalklanten > -4)
{
$tel++;
echo '<li><a href="#'.$tel.'" name="'.$tel.'" onclick="listklant(\'klant.php\',this.name)">'.$tel.'</a></li>';
$totaalklanten = $totaalklanten - 5;
}
echo '</ul>';
echo '<div class="changeme" id="default">';
//Lots of query of php stuff here to execute
echo '</div>
The div with the class 'changeme' is the victim.
My Ajax code so far:
xmlhttp = new XMLHttpRequest();
function listklant(serverPage, pagenum)
{
xmlhttp.open("GET", serverPage);
document.getElementsByClassName('changeme').id = pagenum;
alert(document.getElementById(pagenum));
alert(document.getElementsByClassName('changeme').id);
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
The first alert gives me 'null' :(...
Yet the second alert gives me the right value, so 'pagenum' was applied succesfully.
What am I doing wrong? And how to fix it?
(If there is anything else I can improve, please give a shout)