title: How to transfer a variable to a external js file in javascript?
body: <p><strong>Case 1:</strong> I have passed a variable to a external js file like this</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  var data1, data2, data3, data4;
  
  function plotGraph() {
      var oHead1 = document.getElementsByTagName('HEAD').item(0);
      var paramScript = document.createElement("script");
      paramScript.type = "text/javascript";
      paramScript.setAttribute('data1', data1);
      paramScript.setAttribute('data2', data2);
      paramScript.setAttribute('data3', data3);
      paramScript.setAttribute('data4', data4);
      oHead1.appendChild(paramScript);
      var oHead = document.getElementsByTagName('HEAD').item(0);
      var oScript = document.createElement("script");
      oScript.type = "text/javascript";
      oScript.src = "js/graph.js";
      oHead.appendChild(oScript);
  }
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>Case 2:</strong> I even tried passing it like this using jquery</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;   
  
      function plotGraph() {
          var data1, data2, data3, data4;
          $.getScript("js/graph.js");
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>In the first case which is working but i had to create global variables… I dont want this…</p>
  
  <p>In the second case which is not working has local variables which are not recognized in the js file..</p>
  
  <p>How shall i do it? Any suggestions?</p>