Hi,
I've got three html table cells setup so when I click on one of them I simulate a traffic light system (and call some ajax to post the result).
<td onclick=\"togCell('green'); makemyPOSTRequest('$myvar', '3')
<td onclick=\"togCell('amber'); makemyPOSTRequest('$myvar', '2')
<td onclick=\"togCell('red'); makemyPOSTRequest('$myvar', '1')
The javascript I'm using has worked fine, up until the point that I now have the result from the traffic light saved in a database. When my php script loads it checks the result and changes the background accordingly when the page loads.
The issue is that say the traffic light loads as red, now if I click on yellow the two cells yellow and red .. if that makes sense. How do I nuetralise the red? ... or any other color. Here's the javascript I'm using:
Code:
<script type=\"text/javascript\">
var el
function togCell(col){
if (typeof event!=='undefined')
el=event.srcElement
for (var i = 0; i < el.parentNode.cells.length; i++)
el.parentNode.cells[i].style.backgroundColor=''
el.style.backgroundColor=col
}
if (window.addEventListener)
window.addEventListener('click', function(e){el=e.target}, true)
</script>