fex
Jul 2nd 2008, 2:51 am
Hi,
I wrote a Javascript to see who's logged in on my website. In the script I simply create a string of the names of the people who are online.
I was wondering how I could get that string into <p></p> tags on my webpage.
I'm not sure about the return statement to retreive the string, maybe I need to use print or echo in php (with the js inside the echo).. That's why I'm asking here :)
<script type="text/javascript">
function onlineMembers(){
var usersOnline = new Array(7);
var users = new Array(7);
online = "";
usersOnline[0] = "laurens";
usersOnline[1] = "maarten";
usersOnline[2] = "jana";
usersOnline[3] = "leen";
usersOnline[4] = "pipi";
usersOnline[5] = "salm";
usersOnline[6] = "gerry";
users [0] = "Laurens";
users [1] = "Maarten";
users [2] = "Jana";
users [3] = "Leen";
users [4] = "Pipi";
users [5] = "Salm";
users [6] = "Gerry";
if(document.cookie.length > 0){ // if there are any cookies
for(i=0; i<7; i++){
search = usersOnline[i] + "=";
offset = document.cookie.indexOf(search);
if(offset != -1){ // if cookie exists
online = online + "» " + users[i] + "\n\n"; // Second array for capitals
}
}
}
else{
online = "Geen leden online"; // When no members online
}
return online;
}
</script>
I wrote a Javascript to see who's logged in on my website. In the script I simply create a string of the names of the people who are online.
I was wondering how I could get that string into <p></p> tags on my webpage.
I'm not sure about the return statement to retreive the string, maybe I need to use print or echo in php (with the js inside the echo).. That's why I'm asking here :)
<script type="text/javascript">
function onlineMembers(){
var usersOnline = new Array(7);
var users = new Array(7);
online = "";
usersOnline[0] = "laurens";
usersOnline[1] = "maarten";
usersOnline[2] = "jana";
usersOnline[3] = "leen";
usersOnline[4] = "pipi";
usersOnline[5] = "salm";
usersOnline[6] = "gerry";
users [0] = "Laurens";
users [1] = "Maarten";
users [2] = "Jana";
users [3] = "Leen";
users [4] = "Pipi";
users [5] = "Salm";
users [6] = "Gerry";
if(document.cookie.length > 0){ // if there are any cookies
for(i=0; i<7; i++){
search = usersOnline[i] + "=";
offset = document.cookie.indexOf(search);
if(offset != -1){ // if cookie exists
online = online + "» " + users[i] + "\n\n"; // Second array for capitals
}
}
}
else{
online = "Geen leden online"; // When no members online
}
return online;
}
</script>