-5

I have two javascript files and one html page. i want to include a js file to another js file but i dont know how to include js file to another one.

anyone can please help me?

following is my code

html code:

   <html lang="en">
   <head>
   <script src="main.js" ></script>

   </head>
   <body onload="show()">
   </body> </head>
   </html>

following are the javascript files:

1.js

  var x=10;
  function show()
  {
     setvalue(x)
   }


2.js

   var D=;
   function setvalue(x)
   {
     D = x;
     alert(D);
   }
PM 77-1
  • 12,933
  • 21
  • 68
  • 111
Touqeer
  • 77
  • 9
  • possible duplicate http://stackoverflow.com/questions/3809862/can-we-call-the-function-written-in-one-javascript-in-another-js-file – Mukul Goel Apr 18 '16 at 15:04
  • @MukulGoel duplicate of : http://stackoverflow.com/questions/5892845/how-to-load-one-javascript-file-from-another. you have your answer in the lnik i provided. – Walfrat Apr 18 '16 at 15:05
  • 2.js isn't valid, please read https://developer.mozilla.org/en-US/docs/Web/JavaScript – dsgriffin Apr 18 '16 at 15:09
  • @Walfrat: My answer? I didnt ask the question. Thanks for adding the link though. That should be helpful for OP. – Mukul Goel Apr 18 '16 at 20:41

1 Answers1

-1

if it's just a matter of accessing the functions and objects in the first javascript file just do something like this: <script src="main1.js"></script> <script src="main2.js"></script>

this way any function in main1.js will be available in main2.js

Ayo K
  • 1,719
  • 2
  • 22
  • 34