title: Get value from one function and put it into another function
body: <p>I need to get the value of <code>inputScore</code> currently held in the <code>extractVariable</code> function into the <code>assignValue</code> function (this function gives the value of <code>inputScore</code> to an Index.html page). I tried to store <code>inputScore</code> in a global object to solve scope issues, but inside <code>assignValue</code> the <code>global.scoreValue</code> variable is undefined. How can I get inputScore into assignValue please? New to programming - any help appreciated. Thanks.</p>
  
  <pre><code>global = {};
  
  
  function extractVariable(inputScore) {
  
     global['scoreValue'] = inputScore;
  
  };
  
  
  function assignValue() { 
  
      document.getElementById("inputScore").value = global.scoreValue;
  
  };
  </code></pre>
  
  <p>Thanks for everyone’s help. I am so close to solving what I need to do. The issue seems to be getting <code>inputScore</code> into the <code>Index.html</code> page. I should have posted all of my code in the first place. Apologies. <code>index.html</code> is a separate file, which has a link to the javascript file (<code>Game.js</code>). I have tested the link and it is working. When a button is pressed in <code>Game.js</code>, <code>index.html</code> loads, reads the <code>assignValue</code> function in <code>Game.js</code>, and inserts the players score (<code>inputScore</code>) into an input value in a form. At the moment all that is being inserted into the form is:
  <a href="https://i.stack.imgur.com/Qirkp.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qirkp.jpg" alt="enter image description here"></a><br>
  I cannot figure out why it is not working. I have included code from both files below. Any help is once again appreciated.</p>
  
  <p>Game.js code:</p>
  
  <pre><code>function extractVariable(inputScore) {
  
  return inputScore;
  
  
  };
  
  
  function assignValue(inputScore) {  
       document.getElementById("playerScore").value = inputScore;
  
  };
  
  
  
  var CrystalRunner = CrystalRunner || {};
  
  CrystalRunner.GameState = {
  
  init: function() {
    //...code here
    }, 
  
  
  create: function() {
   //...code here
    },  
  
  
   update: function() {  
  //..code here
  //check if the player needs to die
        if(this.player.top &gt;= this.game.world.height) {
           this.gameOver();
        }
    },  
  
  
   gameOver: function(){
  
      //..code here
  
      this.updateHighscore();
  
      //..code here
  
     },
  
  
    updateHighscore: function(){
      this.highScore = +localStorage.getItem('highScore');
  
  
      if(this.highScore &lt; this.myScore){
              this.highScore = this.myScore;
  
              this.inputScore = this.highScore; 
  
  
              this.submitScoreButton = this.game.add.sprite(this.game.world.centerX-135, this.game.world.centerY+100, 'submitScoreButton');
  
              this.submitScoreButton.events.onInputUp.add(function() {
  
                      window.location.href = "index1.php"; 
  
                }, this);
  
          extractVariable(this.inputScore);
        }
  
  
        localStorage.setItem('highScore', this.highScore);
    },
  
  
  };
  </code></pre>
  
  <p>Index.html code:</p>
  
  <pre><code>&lt;?php
  require_once 'dbconnect.php';
  
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;title&gt;Crystal Candy Game Login&lt;/title&gt;
  
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  
      &lt;link rel="stylesheet" href="css/bootstrap.min.css" type="text/css"/&gt;
      &lt;link href="css/style.css" rel="stylesheet"&gt;
  
  
  &lt;/head&gt;
  
  
  &lt;body onload="assignValue(extractVariable())" class="bg"&gt; 
  
  
      &lt;div id="preloader"&gt;
          &lt;div id="status"&gt;&amp;nbsp;&lt;/div&gt;
      &lt;/div&gt;&lt;!--preloader--&gt;
  
  
      &lt;div class="wrapper"&gt;
  
  
          &lt;div id="main"&gt;
  
          &lt;!-- Form --&gt;
          &lt;form id="form-style" method="post" action="crystalhandle.php" autocomplete="off"&gt;
  
  
                      &lt;div class="form-group"&gt; 
                          &lt;label class="header-text"&gt;&lt;span&gt;First Name&lt;/span&gt;&lt;/label&gt;
                          &lt;input class="form-control" type="text" id="name" name="username" placeholder="Name" title="Please enter your Firstname" required=""&gt;
                      &lt;/div&gt;
  
  
                      &lt;div class="form-group"&gt; 
                          &lt;label class="header-text"&gt;&lt;span&gt;Score&lt;/span&gt;&lt;/label&gt;
                          &lt;input class="form-control" type="tel" id="playerScore" name="score" value="" readonly&gt;
                      &lt;/div&gt;
  
  
                      &lt;div class="w3ls-btn form-group"&gt;       
                          &lt;div class="wthreesubmitaits"&gt;
                          &lt;input type="submit" name="signup" id="reg" class="button" id="next1" value="Send" style="font-family: sans-serif; font-size: 17px; font-weight: bold;"
                          &lt;/div&gt; 
                      &lt;/div&gt;
  
  
          &lt;/form&gt;
  
  
          &lt;/div&gt;
  
      &lt;/div&gt;
  
  &lt;div id="bodytext"&gt;&lt;/div&gt;
  
  
       &lt;script type='text/javascript' src='js/jquery-2.2.3.min.js'&gt;&lt;/script&gt;
       &lt;script type="text/javascript" src="js/phaser.min.js"&gt;&lt;/script&gt;
       &lt;script type="text/javascript" src="js/states/Game.js"&gt;&lt;/script&gt;
  
           &lt;script&gt;
              $(window).on('load', function() {
              $('#status').fadeOut(); 
              $('#preloader').delay(350).fadeOut('slow'); 
              $('body').delay(350).css({'overflow':'visible'});
  
  
              })
      &lt;/script&gt;
  
  &lt;/body&gt;
  
  
  &lt;/html&gt;
  </code></pre>
  
  <p>I have done the following changes, I think a solution is at hand. In <code>Index.html</code> I changed the following line by removing <code>inputScore</code>:</p>
  
  <pre><code>&lt;body onload="assignValue(extractVariable())" class="bg"  &gt;
  </code></pre>
  
  <p>In <code>Game.js</code> I find that if I hard code a value into the <code>extractVariable</code> function (see below), the hard coded value is passed into the <code>value</code> attribute of the <code>&lt;input&gt;</code> tag in <code>Index.html</code> which is what I want it to do. However, I still cannot figure out why this only works with a hard coded value? </p>
  
  <pre><code>function extractVariable(inputScore) {
    inputScore = 27; //hard coded value works. Why?
  return inputScore; 
  
  };
  
  
  function assignValue(inputScore) {  
    console.log(inputScore); //this console.logs the hard coded value from 
    //extractVariable like it should do
       document.getElementById("playerScore").value = inputScore;
  
  };
  </code></pre>