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 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2004
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help With "clearTimeout()"

    good day -

    i am trying to make a search field disappear after a certain amount of time if it is left blank. also, if the user clicks outside of the field, it disappears... you can see a mock page here (look at the source also)... the problem that i'm having is that when the focus is removed from the search field, it should clear the timeOut that is set (so if the user clicks on search again to bring the field up, the timeOut is restarted)... i hope that makes sense

    any help is greatly appreciated...
    note: currently only works in IE... i think...

    thanks!

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Not sure if I fully understand your question but,

    add clearTimeout('t'); to the following

    function showSearch() {
    clearTimeout('t');
    document.all['searchtext'].style.display="none";
    document.all['searchfield'].style.display="inline";
    document.form.t1.focus();
    t=setTimeout("hideSearch()",6000);
    }

    function hideSearch() {
    if(document.form.t1.value==""){
    document.all['searchtext'].style.display="inline";
    document.all['searchfield'].style.display="none";
    clearTimeout('t');
    }
    }

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Remove the quotes around t.

    clearTimeout(t);

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Oops!

    Now I'm really embarrassed, I see the quotes but cannot think for the life of me why I put them in


  •  

    Posting Permissions

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