0

I need to insert the results of a script inside another script which is being sent to Google Reviews. I have this so far, which extracts and displays the last 2 characters of a country code:

onDOMContentLoaded = (function(){
    var str = "United Kingdom UK";
    var res = str.slice(-2);
    document.getElementById("demo").innerHTML = res;
})();
<p id="demo"></p>

This shows the code inside a p tag, but I need it to display in the code below:

window.renderOptIn = function() {
    window.gapi.load('surveyoptin', function() {
      window.gapi.surveyoptin.render(
        {
          "delivery_country": "RESULT GOES HERE",
          });
    });
  }

1 Answer 1

2

It looks like all you need to do is run that window function instead of the DOM manipulation you had already. So the first block would become:

onDOMContentLoaded = (function(){
    var str = "United Kingdom UK";
    var res = str.slice(-2);
    document.getElementById("demo").innerHTML = res;
    window.renderOptIn(res);
})();

and the window function should be changed a bit to this:

window.renderOptIn = function(res) {
    window.gapi.load('surveyoptin', function() {
      window.gapi.surveyoptin.render(
        {
          "delivery_country": res,
          });
     });
  }

Let me know if you have any other questions. And definitely throw some console.logs in there to make sure everything is firing at the right time with the right info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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