Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    body onload setinterval

    I found a little chat script online and I wanted to check it out. When I integrated it into a page I created, for some reason this will not work correctly

    <body onload="setInterval('chat.update()', 1000)">

    I tested it with two different browswers open

    Lets say on two different browser windows you have user1 and user2

    if user1 types 'Hello'
    it will not show up on user2 window
    but if user2 types 'Hi'

    then on user2 window it will say
    user1 says Hello
    user2 says Hi

    so basically for user1 to see what user2 has wrote, user1 has to type something first and send it to see what user2 said.

    hope you understand, if you would like I could post up the code.

  • #2
    New Coder
    Join Date
    Mar 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I forgot to say that on the original script, within the body tags, there was no PHP code. But on my page, i have php within the body tags, does have anything to do with it?

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,899
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    chat.update is not a valid name for a function (may not contain a dot).
    Change it to chat_update.



    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • #4
    New Coder
    Join Date
    Mar 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    actually i got rid of the body onload and used a window onload js function and everything seems to be ok now.

  • #5
    New Coder
    Join Date
    Mar 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is what the was for

    function Chat () {
    this.update = updateChat;
    this.send = sendChat;
    this.getState = getStateOfChat;
    }

  • #6
    Regular Coder
    Join Date
    Mar 2006
    Posts
    726
    Thanks
    35
    Thanked 132 Times in 123 Posts
    Your object was 'Chat.update', not the 'chat.update'-
    and you really ought to allow for quitting any timed event,
    by giving the timer a reference

    Code:
    onload= function(){
    Chat.timer=setInterval(Chat.update, 1000);
    }
    
    //clearInterval(Chat.timer)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •