How to call transfer a variable to a external js file in javascript?
===

**Case 1:** I have passed a variable to a external js file like this

    <script type="text/javascript">
    
    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);
    
    }
    
    </script>

**Case 2:** I even tried passing it like this using jquery

<script type="text/javascript">   
    
    function plotGraph() {

    var data1,data2,data3,data4;
    
    $.getScript("js/graph.js");
    
    }

In the first case which is working but i had to create global variables… I dont want this…

In the second case which is not working has local variables which are not recognized in the js file..

How shall i do it? Any suggestions?
