0

I have 2 js files one is the reusable js function . I would like to call file2.js functions in file1.js . But its not invoking the function from file2.js function

please find my below code for

file1.js

<script src="/sites/ECM/SiteAssets/Jquery/jquery-1.11.2.min.js"></script>
<script src="/sites/ECM/SiteAssets/Jquery/file2.js"></script>

<script>
$(document).ready(function(){

ArrangeChoices("Check Boxes",4);
});

</script>

file2.js

<script src="/sites/ECM/SiteAssets/Jquery/jquery-1.11.2.min.js"></script>
<script src="/sites/ECM/SiteAssets/Jquery/jquery.SPServices-2014.01.min.js"></script>

<script>
$(document).ready(function(){


});

function ArrangeChoices(cName,count)
{
alert(cName - count);
$().SPServices.SPArrangeChoices({
 columnName: cName,
 perRow: count
});
}

</script>
user3476088
  • 85
  • 1
  • 3
  • 14
  • You are using script tags inside of a javascript file. I don't think this will work to begin with. The files included at the top should be included from your HTML file while the javascript files should have no HTML tags. – pcnate May 28 '15 at 00:25
  • Hi pcnate Thanks for your reply These files are used in sharepoint and this is how it will be done in SharePoint for adding Javascript if i include the code in one file it is working fine. – user3476088 May 28 '15 at 00:57
  • Is the function accessible from a Chrome console? – pcnate May 28 '15 at 01:00
  • but it is throwing error saying that the function is undefined [link](http://oi57.tinypic.com/296kleb.jpg) see the error message screen shot – user3476088 May 28 '15 at 01:09
  • 1
    Likely, what is going on is that jquery is being loaded by a js file and not ready when you setup the document.ready. You may have to resort to including the 2nd file as you do jquery from the first file. I have in the past manually loaded jquery into a sharepoint page via javascript via a method like this: [link](http://stackoverflow.com/questions/4523263/load-jquery-from-external-source-if-not-loaded). Then execute a function as a callback once that has completed loading and call your function then. – pcnate May 28 '15 at 01:14

1 Answers1

0

You included jquery-1.11.2.min.js for both js file. Get rid of one in file1.js.

Lumi Lu
  • 3,289
  • 1
  • 11
  • 21
  • This is avoiding the fact that these are javascript files. – pcnate May 28 '15 at 00:38
  • I have commented out one of the jquery-1.11.2.min.js from file1.js but still its not invoking the function from file2 – user3476088 May 28 '15 at 00:54