Gandalf
Gandalf

Reputation: 13683

Javascript Problem

I am trying to populate list boxes with data and at the same time display the number of users currently logged in.

I have the following code.

<body onload = "getNumberOfOnlineUsers();" onbeforeunload = "leaveChat();">
<body onload="initListGroup('links', document.forms[0].category, document.forms[0].site);">

The two chain boxes are rendered but the data is not populated.The number of current users too is displayed.

When i put,<body onload="initListGroup('links', document.forms[0].category, document.forms[0].site);">

above <body onload = "getNumberOfOnlineUsers();" onbeforeunload = "leaveChat();">

The chaine boxes are now working okay,but the number of users is not displayed.What could be the problem?.

Upvotes: -1

Views: 185

Answers (3)

Richard Fawcett
Richard Fawcett

Reputation: 2809

You can only have one <body> element in your page. The second one is being ignored. Instead, you could try this:

<body onload = "getNumberOfOnlineUsers(); initListGroup('links', document.forms[0].category, document.forms[0].site);" onbeforeunload = "leaveChat();">

Upvotes: 1

FatherStorm
FatherStorm

Reputation: 7183

yo can't use two body tags.. do it like this:

<script>
  function init(){
    getNumberOfOnlineUsers();
    initListGroup('links', document.forms[0].category, document.forms[0].site);

  }
  function destruct(){
    leaveChat();
  }

</script>
<body onload='init();' onunload='destruct();'>

Upvotes: 0

Jason Benson
Jason Benson

Reputation: 3399

if it's one page you should have only one body tag.

try

<body onload="getNumberOfOnlineUsers();initListGroup('links', document.forms[0].category, document.forms[0].site;">

Upvotes: 4

Related Questions