SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    455
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    pause a while loop

    is there a way to pause a while loop and display a message on each iteration?

  2. #2
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    There is a sleep function in which you can pause number of seconds you specified.

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    455
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but there's no opportunity to display a message. I'm on to rendering javascript in php.

    This displays nicely, but there's no var in it:
    Code:
    <?php
    echo '<script type="text/javascript">';
    echo 'alert("Hello World")';
    echo '</script>';
    ?>
    how do I get the php variable into the JS var when the JS is rendered in php?

    Code:
    $str = "Hello World";
    echo '<script type="text/javascript">';
    echo 'var str = ?????';  
    echo 'alert(str)';
    echo '</script>';

  4. #4
    SitePoint Addict kduv's Avatar
    Join Date
    May 2012
    Location
    Atlanta, GA
    Posts
    244
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $str "Hello World";
    echo 
    '<script type="text/javascript">';
    echo 
    'alert("' $str '");';
    echo 
    '</script>'
    Or:
    PHP Code:
    $str "Hello World";
    echo 
    '<script type="text/javascript">';
    echo 
    'var str = "' $str '";';  
    echo 
    'alert(str);';
    echo 
    '</script>'

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    455
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks kduv. That fits the bill!.

    This is one for my topic scrapbook. This one is truly a keeper! I've been needing something like this for years. Before recently, I didn't understand javascript well enough to even ask this question.

  6. #6
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Another way in JS:

    Code:
    displayMessage(data);
    setTimeout(function(){hideMessage();}, 4000);
    The setTimeout() method will run the callback function hideMessage() after 4000 miliseconds. You could use AJAX to post to a PHP page in the callback if you wanted.

    Steve
    ictus==""


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •