Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I need some help.

I have this JavaScript on site that renders a ticker with a value (progressive).

<script src='http://www.externalsite.com/modules/common/getProgBlock.php?progid=1&cbox=all&showlogo=no&currency=USD'></script>

Its rendering is this:

$12,546.07

I tried to parse this JS file:

<?php 
$html_data =  file_get_contents('http://www.externalsite.com/modules/common/getProgBlock.php?progid=1&cbox=all&showlogo=no&currency=USD', 'r');

echo $html_data;

?>

and I get this all JS parameters.

EDIT This is the parsed JS:

var scripts = document.getElementsByTagName('script');
var currentScript = scripts[scripts.length - 1];
currentScript.id = ((currentScript.id.length === 0) ? "mgsProgressiveTickerControlScript" : currentScript.id);

function cleanQueryString(querystring) {
    querystring = querystring.replace(/^[^\?]+\??/, '');
    querystring = querystring.replace('fontfamily', 'font-family').replace('fontsize', 'font-size').replace('fontcolor', 'font-color');
    querystring = querystring.replace('showlogo=yes', 'showlogo=true').replace('showlogo=no', 'showlogo=false');
    querystring = querystring.replace('showcasino=yes', 'showcasino=true').replace('showcasino=no', 'showcasino=false');
    querystring = querystring.replace('showonlycasino=yes', 'showonlycasino=true').replace('showonlycasino=no', 'showonlycasino=false');
    return querystring.toLowerCase();
}
var lowerQueryString = cleanQueryString(currentScript.src);

function parseQueryString(queryString) {
    var queryStringParams = {};
    if(!queryString) {
        return "{}";
    }
    var queryStringPairs = queryString.split(/[;&]/);
    for(var i = 0; i0) {
        txt += " ";
    }
    txt += data[i];
}
return txt;
}
renderTicker = new function () {
    this.init = function (lowerQueryString) {
        document.write("");
        var newScript = document.getElementsByTagName('head')[0].appendChild(document.createElement('script'));
        newScript.id = "mgsProgressiveTickerAsmxScript";
        newScript.setAttribute("type", "text/javascript");
        newScript.src = ((window.location.protocol == 'https:') ? "https://" : "http://") + "www.externalsite.co.uk/ProgressiveTickers/WebServiceProgressiveTicker.asmx/renderTicker?form=json&booIsSecure=" + ((window.location.protocol == 'https:') ? true : false) + "&strProgId=" + getParam('progid', 'jackpot') + "&booShowLogo=" + getParam('showlogo', true) + "&booShowCasino=" + getParam('showcasino', false) + "&booShowOnlyCasino=" + getParam('showonlycasino', false) + "&strFontFamily=" + getParam('font-family', null) + "&intFontSize=" + getParam('font-size', 0) + "&strFontColor=" + getParam('font-color', null) + "&strCurrId=" + getParam('currency', null);
        this.parseResult = function (data, strProgId, strCurrId, booShowOnlyCasino) {
            document.getElementById("progressiveTicker" + strProgId).innerHTML = cleanHTML(data);
            if((document.getElementById("progressiveTicker" + strProgId).innerHTML.length > 0) && (booShowOnlyCasino == 'false')) {
                var scrollScript = document.createElement('script');
                scrollScript.id = "mgsProgressiveTickerScriptScroll";
                scrollScript.setAttribute("type", "text/javascript");
                scrollScript.src = ((window.location.protocol == 'https:') ? "https://" : "http://") + "www.externalsite.co.uk/ProgressiveTickers/WebServiceProgressiveTickerScriptScroll.asmx/renderScript?form=json&strProgId=" + strProgId + "&strCurrId=" + strCurrId;
                document.getElementById("progressiveTicker" + strProgId).parentNode.insertBefore(scrollScript, document.getElementById("progressiveTicker" + strProgId).nextSibling);
            }
        };
    };
};
var mgsProgressiveTickerSharedFunctions = document.getElementById('mgsProgressiveTickerSharedFunctions');
if(mgsProgressiveTickerSharedFunctions === null) {
    var INSERTmgsProgressiveTickerSharedFunctions = document.getElementsByTagName('head')[0].appendChild(document.createElement('script'));
    INSERTmgsProgressiveTickerSharedFunctions.id = "mgsProgressiveTickerSharedFunctions";
    INSERTmgsProgressiveTickerSharedFunctions.src = ((window.location.protocol == 'https:') ? "https://" : "http://") + "www.externalsite.co.uk/modules/common/sharedfunctions.php";
}
document.getElementById(currentScript.id).parentNode.removeChild(document.getElementById(currentScript.id));
renderTicker.init(lowerQueryString);

I need to pass the "progressive value" into a PHP variable to store the same value into a MySql database (I also have a script that can do this).

How can I pass this "value" into a PHP variable? What's the best approach? Please, help. I'm a totally noob in PHP!

Thanks in advance to all!

share|improve this question
That external site's script could be doing anything. Could you show a minimal version of that script? – Matt Ball Jan 21 at 14:51
What exactly is the content of the script? What does echo $html_data print? – Rocket Hazmat Jan 21 at 14:54
JavaScript runs in the browser. Loading a JS file in PHP isn't going to run it. It's just going to return you its source. – Rocket Hazmat Jan 21 at 14:58
@MattBall Yes, sorry. Just added the parsed JS file. Thanks for comment! – Splugged Jan 21 at 15:00
possible duplicate of How to pass JavaScript variables to PHP? – berkes Jan 21 at 17:01

closed as not a real question by Gordon, Chuck Burgess, Goran Jovic, berkes, Sébastien Le Callonnec Jan 21 at 17:11

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

2 Answers

The quickest way to do this would be using jQUery AJAX. Something like this should do the trick:

$.ajax({
    type: POST,
    url: file/location/ajax.php,
    data: { var: variable_to_be_passed }
});

Then in file/location/ajax.php you want:

$var = isset($_POST['var']) ? $_POST['var'] : FALSE;
do_something_with_var...
share|improve this answer

You need to pass the value using AJAX. Here's the manual. Or, you can also just submit the values using submit method.

share|improve this answer
Yes, I tried the submit method but to store the value in database I need to render the page first. Thanks for your comment! – Splugged Jan 21 at 15:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.