matthew9090 Posted April 6, 2011 Share Posted April 6, 2011 i've got this code: <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { var number = 10; var url = "index.php?number=0"; function countdown() { setTimeout(countdown, 1000); $('#box').html("Selecting person in " + number + " seconds"); number --; if (number<0) { window.location = url; number = 0; } } }); </script> <center> <div id="box"> <?php error_reporting(0); $file = file('names.txt'); $rand_line = rand(0, sizeof($file) - 1); $line = $file[$rand_line]; if ($_GET['number']=="0") { echo $line; } else { ?> <script type="text/javascript"> countdown(); </script> <?php } ?> </div> it is meant to when the javascript number = 0 show a random line from file but it comes up with undefined index 'number' on line 28 Link to comment https://forums.phpfreaks.com/topic/232844-execute-php-code-if-javascript-number-0/ Share on other sites More sharing options...
matthew9090 Posted April 6, 2011 Author Share Posted April 6, 2011 now ive tryed another way which works but then won't stop showing names once the timer has finished <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { var number = 2; function countdown() { setTimeout(countdown, 1000); $('#box').html("Selecting person in " + number + " seconds"); number --; if (number<0) { keywords = [ "name1", "name2", "name3", "name4", "name5" ] var keyword = keywords[Math.floor(Math.random()*keywords.length)] document.write(keyword); number = 0; } } countdown(); }); </script> <center> <div id="box"> </div> </center> Link to comment https://forums.phpfreaks.com/topic/232844-execute-php-code-if-javascript-number-0/#findComment-1197613 Share on other sites More sharing options...
spiderwell Posted April 6, 2011 Share Posted April 6, 2011 you might get more response in the javascript forum Link to comment https://forums.phpfreaks.com/topic/232844-execute-php-code-if-javascript-number-0/#findComment-1197630 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.