calling functions in other javascripts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anudu
    New Member
    • Oct 2007
    • 31

    calling functions in other javascripts

    Hi,

    Is there any way to call function in another javascript , as in Object Oriented languages ?

    Anushka
  • lopez
    New Member
    • Mar 2008
    • 6

    #2
    hi there,
    use the below code
    [CODE=javascript]<script language="javas cript">
    function call()
    {
    call2();
    }
    function call2()
    {
    alert("call2 was called");
    }
    <script>
    [/CODE]
    Now do something and call "call()". ur "call2()" will be called by itself........
    regards
    lopez.
    Last edited by gits; Mar 28 '08, 01:39 PM. Reason: added code tags

    Comment

    • anudu
      New Member
      • Oct 2007
      • 31

      #3
      Originally posted by lopez
      hi there,
      use the below code
      <script language="javas cript">
      function call()
      {
      call2();
      }
      function call2()
      {
      alert("call2 was called");
      }
      <script>

      Now do something and call "call()". ur "call2()" will be called by itself........
      regards
      lopez.
      thanks lopez.

      but my problem is, acording to your example if call2() is written in another .js file can I access it within call() method? as we do in OO languages, we create an object from the class and access its method. actually i am dealing with two .js files. i want to access a function in one .js file from another .js file.

      Comment

      • vee10
        New Member
        • Oct 2006
        • 141

        #4
        Hi,

        yes u can do this

        i will give u simple example

        Code:
        sampleA.js
        function CallmethodA()
        {
        //some logic 
        }
        sampleB.js //this will call sampleA.js methods
        function CallMethodB()
        {
        //some logic
        CallmethodA()
        }
        
        <html>
        <head>
        <script type="text/javascript" src="sampleA.js"></script>
            <script type="text/javascript" src="sampleB.js"></script>
            <script type="text/javascript">
           
            function checking()
            {
            call1();
            }
             
            
            </script>
        </head>
        <body onload="checking()">
        </body>
        </html>
        or u can check out this link
        [EDIT]

        Originally posted by anudu
        thanks lopez.

        but my problem is, acording to your example if call2() is written in another .js file can I access it within call() method? as we do in OO languages, we create an object from the class and access its method. actually i am dealing with two .js files. i want to access a function in one .js file from another .js file.
        Last edited by gits; Mar 28 '08, 01:37 PM. Reason: removed link to competing forum ... according to posting guidelines

        Comment

        Working...