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
    Regular Coder
    Join Date
    Jan 2004
    Location
    Port Huron, MI, U.S.A.
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arguments in setInterval func

    I have a script with a function that triggers a 'setInterval' but the function the interval triggers has an arguement. How can I do this?
    Note:the function is also triggered before the interval starts so that there is no delay.
    This is the part of the code I'm talking about.
    (turnI is the function to be triggered.)
    Code:
    .....
    function turny(ITaa) {
    var Gunck=turnI(ITaa);
    Timer=setInterval(Gunck,503)
    	}
    .....
    Oh, was I supposed to put something here? ........

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    I can't be sure because you are only posting part of the code but from what you are showing this may answer your question.

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function turnI(ITaa)
    {
    	alert();
    	x=ITaa+1;
    	alert(x);
    }
    
    function turny(ITaa) {
    Timer=setInterval("turnI("+ITaa+")",503)
    	}
    	
    </script>
    </head>
    <body onload="turny(2)">
    </body>
    </html>
    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,960
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Quote Originally Posted by Bobo
    I have a script with a function that triggers a 'setInterval' but the function the interval triggers has an arguement. How can I do this?
    Note:the function is also triggered before the interval starts so that there is no delay.
    This is the part of the code I'm talking about.
    (turnI is the function to be triggered.)
    Code:
    .....
    function turny(ITaa) {
    var Gunck=turnI(ITaa);
    Timer=setInterval(Gunck,503)
    	}
    .....
    Code:
    function turny(ITaa) {
      var Gunck=turnI(ITaa);
      Timer=setInterval(function(){turnI(ITaa)},503);
    }
    But if you want to support IE5, do what Basscyst suggested. But if iTaa is a string and not a number, you have to surround it with quotes.
    Code:
    function turny(ITaa) {
      Timer=setInterval("turnI('"+ITaa+"')",503)
    }
    But the difficult part of that is if the argument has single quotes in it, you have to replace ' with \'. The same is true if you use double quotes as string delimiter and the argument has double quotes in it.

  • #4
    Regular Coder
    Join Date
    Jan 2004
    Location
    Port Huron, MI, U.S.A.
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I want IE5 supported so I took B's suggestion. I added the single quotes and all is well. Thanks a lot!
    Last edited by Bobo; 07-13-2004 at 04:19 PM.
    Oh, was I supposed to put something here? ........


  •  

    Posting Permissions

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