php - Looping a javascript function onload -
i want phone call javascript
many times needed within php
while loop. i'm trying figure out proper way phone call multiple instances of function on load.
here code:
<script> var interval; var minutes = 1; var seconds = 10; var nbcounters = '<?php echo $nbcounters ;?>' window.onload = function() { (i = 0; < nbcounters; i++) { countdown('c'.'<?php echo $value ;?>'); } } function countdown(element) { interval = setinterval(function() { var el = document.getelementbyid(element); if(seconds == 0) { if(minutes == 0) { location.reload(true); } else { minutes--; seconds = 60; } } if(minutes > 0) { var minute_text = minutes + (minutes > 1 ? ' min(s)' : ' min'); var secound_text = ''; el.innerhtml = 'ready in ' + minute_text; } else { var minute_text = ''; var second_text = seconds + (seconds > 1 ? ' sec(s)' : ' sec'); el.innerhtml = 'ready in ' + second_text; } seconds--; }, 1000); } </script> <?php $nbcounters = 5; $value = 0; while ($value < $nbcounters) { echo "<div id='c$value'></div><br>"; $value++; } ?>
you mixing when utilize php
loop , when js
loop. utilize php
loop generate n
calls js
function here:
window.onload = function() { <?php ($i = 0; $i < $nbcounters; $i++) { echo "countdown('c".<?php echo $i ;?>."');"; } ?> }
this result in html like:
window.onload = function() { countdown('c0'); countdown('c1'); countdown('c2'); countdown('c3'); countdown('c4'); }
but sure first set php
parameters before loop.
javascript php while-loop countdown
No comments:
Post a Comment