/    Sign up×
Community /Pin to ProfileBookmark

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:

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

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

[code=php]<?php
$num = rand (1,5);
class XmlToJson {

public function Parse ($url) {

$fileContents= file_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($jsone, true);

$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;
}
?>

[/code]

bbjackpot.php

[code=php]<?php

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

$jsond = json_decode($jsone, true);

$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>’; ?>
[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERMay 24.2013 — 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.
×

Success!

Help @rbrown spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...