Sunday, 18 August 2013

Several 'onclick' events for 1 div (change div id)

Several 'onclick' events for 1 div (change div id)

I have 2 divs.

Once 1 of the 2 divs has been selected, the 'id' of each will change to
either divActive, or divInactive so the active one can be highlighted
using css.
Is it possible to do this even though i already have an 'onclick' action
associated with each div?
Here are my divs:
<div class="statusOption" onclick="loadXMLDoc('indexEveryone')">Everyone,
everywhere</div>
<div class="statusOption" onclick="loadXMLDoc('indexFav')">Favourites
Only</div>
Here is my current javascript:
<script>
function loadXMLDoc(pageName)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("centreCont").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","../home/" + pageName + ".php",true);
xmlhttp.send();
}
</script>

No comments:

Post a Comment