Posted By

apphp-snippets on 03/03/13


Tagged

javascript setInterval


Versions (?)

Pass Parameters in SetInterval() function in JavaScript


 / Published in: JavaScript
 

URL: http://www.apphp.com/index.php?snippet=javascript-pass-parameters-in-setinterval

You may perform this work with two ways: pass it directly like described in sample #1 or use an anonymous function like its shown in sample #2.

  1. <script type="text/javascript">
  2. // sample #1
  3. setInterval('alert_function(1)', 1500);
  4.  
  5. // sample #2
  6. setInterval(function(){ alert_function(10); }, 1500);
  7.  
  8. // user's alert function
  9. function alert_function(val){
  10. alert("Passed parameter is: " + val);
  11. }
  12. </script>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Arindam_Mojumder on April 4, 2014

There is another way to send paramas.

// sample #3 setInterval(alert_function, delayValue, param 1, param 2, ....);

Posted By: Arindam_Mojumder on April 4, 2014

There is another way to send paramas.

// sample #3 setInterval(alert_function, delayValue, param 1, param 2, ....);

You need to login to post a comment.