Javascript: message by login
-
22-07-2019 - |
Question
i have this chatbox, and when users login i want it to send a message like this:
Admin: User is online
I really want to use a javascript code for this, because i can work with it quite good. I already have some example, but the problem here is that it does not do something until it is called to do it's function. THATS what i want to achieve, just that when the page is opened up, it does that function one time.
function onLine(message)
{
document.writeform.bericht.value+=message;
document.writeform.bericht.focus();
write1();
}
explanation: onLine is the function and (message) tells what it should say. For example:
...
onclick="onLine('User is online');"
...
the function write1() sends it.
HELP?!
Solution
Do you want to run that function once when the page is loaded? If so, you have many possible ways to do it. A couple of simple ones:
<body onload="onLine('User is online')">
This will call the function when all the page components are loaded. You could also add this to the end of the page:
<script type="text/javascript">
onLine('User is online');
</script>
There are also javascript libraries like jQuery and prototype, which you should have a look at if you haven't yet.