php - Looping a javascript function onload -


I want to call a javascript as often as PHP while loop I am trying to extract the proper way of calling several examples of functions on load.

Here is the code:

  & lt; Script & gt; Var interval; Var minutes = 1; Var seconds = 10; Var nbcounters = '& lt ;? Php echo $ nbcounters ;? & Gt; ' Window.onload = function () {for (i = 0; i & lt; nbcounters; i ++) {Countdown ('c'. & Lt ;? php echo $ value ;; & gt; '); }} Function countdown (element) {interval = set interval (function () {varel = document.getElementById (element); if (seconds == 0) {if (minute == 0) {location.reload (true); } And (min -; seconds = 60;}} if (min> gt;) {var min_development = minutes + (min> gt; 1? 'Min (s)': 'min'); var secound_text = '' ; El .innerHTML = 'Ready' + minute_text;} Other {var minute_text = ''; var seconds_text = second + (seconds> 1? 'Seconds'): 'sec'); el.innerHTML = 'ready' + Seconds_text;} seconds -;}, 1000); } & Lt; / Script & gt; & Lt ;? Php $ nbcounters = 5; $ Value = 0; While ($ value    

You are mixing when using php loop And use the js function to call js loop basically php to loop n here:

  window.onload = function () {& lt ;? For Php ($ i = 0; $ i & lt; $ nbcounters; $ i ++) {resonant "countdown ('c'. & Lt ;? php echo $ i ?; & gt;. ''), "; }? & Gt; }  

This will be similar to HTML:

  window.onload = function () {countdown ('c0'); Countdown ('c1'); Countdown ('c2'); Countdown ('C3'); Countdown ('C4'); }  

But make sure to set the php parameter first before this loop.


Comments