We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

indianocean on 05/02/07


Tagged


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

vali29


JavaScript to import another JavaScript


Published in: JavaScript 


URL: http://www.searchengineforums.com/apps/searchengine.forums/action::thread/forum::coding/thread::1155325739/

  1. index.html:
  2. <html>
  3. <head>
  4. <script id="jsfile1" src="main.js"></script>
  5. <script id="jsfile2"></script>
  6. </head>
  7. <body>
  8. <P>Header</P>
  9.  
  10. <div id=DataContainer>
  11. <script type="text/JavaScript"><!--
  12. DoRoutine('001');
  13. // --></script>
  14. </div>
  15.  
  16. <P>Footer</P>
  17. </body>
  18. </html>
  19.  
  20. main.js:
  21. function DoRoutine(routineID)
  22. {
  23. document.getElementById('jsfile2').src = routineID + ".js";
  24. }
  25.  
  26. 001.js:
  27. function getDATA () {
  28. var data = new Array(3);
  29. data [1] = "This is DATA 1, ";
  30. data [2] = "This is DATA 2, ";
  31. data [3] = "This is DATA 3";
  32.  
  33. document.getElementById("DataContainer").innerHTML = data[1] + data[2] + data[3];
  34.  
  35. }
  36.  
  37. getDATA ();

Report this snippet 

You need to login to post a comment.