echo "<div id=\"userinfo\"><p><strong>$username</strong></p><p>Bids: <strong>$bids</strong></div>
<script>
var usn = document.getElementById('userstuff');
menu = document.getElementById('userinfo');
if (usn)
{
usn.addEventListener('click',toggle_menu);
}
function toggle_menu()
{
alert('clicked');
if (menu.style.display == '')
{
menu.style.display='block';
}
else if (menu.style.display == 'block')
{
menu.style.display='';
}
}
</script>";
This code works on the first click. By default, the display value in menu is set to 'none'. The first click, the user is alerted 'clicked' and the menu becomes visible. However, on more clicks, the user is alerted 'clicked' but the menu does not become invisible and the 'hidden' alert does not show.