How to call function in the js file from other js file and why EventListener don't work ? RRS feed

  • Question

  • Hey everyone I need some help with the split template, first I would like to understand why I can setup an  event listener in split.js file but than I am trying using the same script at data.js it's not working here the code I made just to test that : 

     ui.Pages.define("/pages/split/split.html", {
            ready: function (element, options) {
                document.getElementById("button1").addEventListener("click", createFile, false);
                function createFile() {
                    var outputDiv = document.getElementById("output");
                    outputDiv.innerHTML = "The file ";
        } );

    I tryied to play it as much as I can but nothings helps , same script work in split.js but not working in data.js , what I am doing wrong ? 

    And one more thing, how can I call a function from data.js to split.js I set it up right at the html source buy putting data.js source first and after it the split.js source, but yet the split.js don't recolonize the function witch I made in data.js, If someone could explain me I would be very thankful ! Thank's ahead to everyone who helps :) 

    Tuesday, June 11, 2013 8:03 AM


  • Hi,

    You need to declare the functions in Global scope:

    For example in data.js

    WinJS.Namespace.define("MyFunctions", {
            SampleFunction: sampleFunctionImpl,
            SampleFunction2: sampleFunctionImpl2,
    function sampleFunctionImpl()
    // Implementation here
    function sampleFunctionImpl2()
    // Implementation here

    from split.js you can call these above two functions in data.js by :


    Hope this helps..

    - Girija

    Please mark responses as answered if it helped you.. This helps others... - Girija Shankar Beuria

    • Marked as answer by Daniel Iliya Thursday, June 13, 2013 3:32 PM
    Wednesday, June 12, 2013 7:11 PM