www.webdeveloper.com
Results 1 to 2 of 2

Thread: javascript only firing once??!!!!!

  1. #1
    Join Date
    Jul 2007
    Posts
    76

    javascript only firing once??!!!!!

    hi there,

    i dont know whether this is more of a php issue or javascript issue but I would appreciate if someone could put me out of my misery as i've been on this for days.

    basically i have a php file using a switch statement to randomly choose from a list of messages to display on an online web banner:

    http://www.manninmedia.co.im/micro/frame-test.html

    all the messages work as they should, however on the second message (case 2) required a little extra javascript coding (via a php include of my bbjackpot.php) to apply an increment to a dynamic value.

    now because the messages are chosen randomly at every load, occasionally messages will get displayed twice once after the other.

    now thats no problem, but with the second message it doesnt execute the javascript in bbjackpot.php a second time and therefore the message turns up blank??

    i am getting pretty desperate with this and appreciate anyones help, my code is below:

    ajax.php

    PHP Code:
    <?php
    $num 
    rand (1,5); 
    class 
    XmlToJson {

             public function 
    Parse ($url) {

                     
    $fileContentsfile_get_contents($url);

                     
    $fileContents str_replace(array("\n""\r""\t"), ''$fileContents);

                     
    $fileContents trim(str_replace('"'"'"$fileContents));

                     
    $simpleXml simplexml_load_string($fileContents);

                     
    $json json_encode($simpleXml);

                     return 
    $json;

             }

    }

    switch (
    $num)
    {
        case 
    1:

            
    $jsone XmlToJson::Parse("http://www.microgaming.co.uk/pokerfeeds/WebServiceViewOnline.asmx/ViewOnlineXML");

            
    $jsond json_decode($jsonetrue);

            
    $totalPlayers $jsond['GLOBAL']['@attributes']['totalPlayers'];

            
    $filledSeats $jsond['GLOBAL']['@attributes']['filledSeats'];

            echo 
    json_encode('<h2>Total Player Count</h2> ' $totalPlayers ' Players Online'); 
     
            break;

        case 
    2:
        
          
    ob_start();
          include 
    'bbjackpot.php';
          
    $view ob_get_clean();
             echo 
    json_encode(''$view);

          break;

        case 
    3:
            echo 
    json_encode('<h2>The first online poker network</h2> to offer real play poker on Android mobile devices.');

            break;
        case 
    4:
            echo 
    json_encode('<h2>The first online poker network</h2> to offer a fast-fold poker variant, Blaze.');

            break;
        case 
    5:
            echo 
    json_encode('<h2>The first online poker network</h2> management board, created in 2011.');

            break;
    }
    ?>
    bbjackpot.php

    PHP Code:
    <?php


            $jsone 
    XmlToJson::Parse("https://mppv2valueadds3.valueactive.eu/MPP_BadBeatFeed/default.aspx");

            
    $jsond json_decode($jsonetrue);

            
    $name $jsond['data']['struct']['var']['@attributes']['name'];

            
    $initial $jsond['data']['struct']['var']['struct']['var'][0]['number'];

            
    $increment $jsond['data']['struct']['var']['struct']['var'][1]['number']; ?>

            <script>

            function formatDollar(num) {
              var p = (num / 100).toFixed(2).split(".");
              return "&pound;" + p[0].split("").reverse().reduce(function(acc, num, i, orig) {
                  return  num + (i && !(i % 3) ? "," : "") + acc;
              }, "") + "." + p[1];
          }
            var total = <?php echo $initial ?>  // put your initial value here

            var addition = Math.round(<?php echo $increment ?>);
       


            function incrementNumber() {
                var result = total += addition// you can increment by anything you like here
                var jackpot = formatDollar(result);
                    document.getElementById('counter').innerHTML = jackpot;
                }
                // this will run incrementNumber() every second (interval is in ms)
            setInterval(incrementNumber, 1000);
          </script>


          <?php echo '<h2>Bad Beat Jackpot</h2>'?>

          <?php echo '<span id="counter"></span>'?>

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,389
    I don't know enough PHP to tell you what to do, but since you have had so little response, I would suggest posting to the PHP section of the forum.
    Don't know if that will get you to a solution, but at least it might be more eyes on the problem.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles