Pass Parameters in SetInterval() function in JavaScript


/ Published in: JavaScript
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.