On my site, I use an onclick event on a link to call a javascript function (links are located within a WHILE loop from an external php file). The onclick from within the php WHILE loop passes the user picture and a username to a javascript function called ShowUser(). The event correctly generates a username and photo and places it within the innerHTML of a div as follows:
<script language="javascript" type="text/javascript">
function ShowUser(userpic,username) {
var TitleDesc1 = 'Click this photo to learn more about '+username+'';
document.getElementById('UserPicHolder').innerHTML = '<img class="TipTip"
title="'+TitleDesc1+'" src="'+userpic+'" style="width:60px; height:66px" alt="user
picture">';
}
</script>
This works correctly. However, when I try to make the user picture clickable (onclick #2) (by adding a href) to show the user's site statistics the function does not open the Stats Box (a div that should be hidden until the onclick#2 (DisplayUserStats) WITHIN the javascript function):
<script language="javascript" type="text/javascript">
function ShowUser(userpic,username) {
var TitleDesc1 = 'Click this photo to learn more about '+username+ '';
document.getElementById('UserPicHolder').innerHTML = '<a href="#null"
onclick="DisplayUserStats("'+username+'")"><img class="TipTip" title="'+TitleDesc1+'"
src="'+userpic+'" style="width:60px; height:66px" alt="user picture"></a>';
}
</script>
The user's Stats Box div becomes visible, as expected, when the function DisplayUserStats() is empty (as DisplayUserStats() ), but of course the stats are undefined since no username has been defined. It's only when seemingly ANY content is placed inside DisplayUserStats() that the Stats Box div does not open (e.g. DisplayUserStats(dummystring) does not open the Stats Box div. Note that I have tried several other concatenations (thinking I did this incorrectly), for example, +username+ '+username+' username etc. Could someone please shed some light on how the variable username can be passed to the function DisplayUserStats()?