Results 1 to 4 of 4

Thread: global functions

  1. #1
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default global functions

    is it possible to call a function from a different JS file?
    lets say in my header i have 2 different files, can i call a function that resides in "main_2.js" from 'main_1.js'
    ?
    Code:
    <script type="text/javascript" src="js/main_1.js"></script>
    <script type="text/javascript" src="js/main_2.js"></script>

  2. #2
    Join Date
    Jan 2011
    Location
    QLD, Australia
    Posts
    23
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    In a word, YES,

    e.g I have an AJAX formpost script, and a form fieldcheck(sanitizer)
    script, when a user submits the form it calls a function from the fieldcheck
    script and if it passes the check it then calls a function from the formpost script to process the form!

    Cheers!
    Last edited by Oziam; 01-14-2011 at 11:58 PM.

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    just make sure the file the function is in is already loaded before the other script calls it.

  4. The Following User Says Thank You to traq For This Useful Post:

    ggalan (01-15-2011)

  5. #4
    Join Date
    Jan 2011
    Location
    QLD, Australia
    Posts
    23
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    just make sure the file the function is in is already loaded before the other script calls it.
    Yes traq execellent point I neglected to mention, otherwise you will get "Object expected" error message.

  6. The Following User Says Thank You to Oziam For This Useful Post:

    ggalan (01-15-2011)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •