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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    inline setTimeout function problems...

    hey all,

    I have the following code in my 'onkeyup' event, which works fine...

    Code:
    <input type="text" id="txtActivityCode" class="textbox" style="width:211px" onkeyup="setTimeout(displayActivityCodes(this.value), 1000)" />
    however, when i change the onkeyup event to be like so:
    Code:
    <input type="text" id="txtActivityCode" class="textbox" style="width:211px" onkeyup="setTimeout('displayActivityCodes(this.value)', 1000)" />
    which is what is in all the examples i have seen, and also in the firefox error console (useless setTimeout call (missing quotes around argument?)), it wont send the value of this.value...instead it becomes undefined...

    how do i get around this?

    Cheers,
    Justin

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    It doesn't work because setTimeout works in global scope. Meaning, this refers to the global window object not to the HTML control object.

    Change your code to:
    Code:
    <script type="text/javascript">
    function  displayCodes(code){
      setTimeout(function(){displayActivityCodes(code)}, 1000);
    }
    </script>
    <input type="text" id="txtActivityCode" class="textbox" style="width:211px" onkeyup="displayCodes(this.value);" />
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Thanks for your reply...that worked

    im finding im needing more and more functions..so its all abit mind boggling trying to retrace. lol

    Thanks again,
    Justin


  •  

    Posting Permissions

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