Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Function collected in external file - possible?

    Hi - cool forum! This is my first post but *heck* here goes:

    As far as I know a friend of mine put all his javascripts-functions in an external file and then refers to it from his "normal" html file.

    How can I do that?
    I've tried to ask him, but he has'nt answered me yet, so hopefully someone in here answers before him...

    In advance - THX!

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well, as a matter of fact it's very easy! You open a free document, whatever it is! Then you type your functions or variables that you like, then you save the file with the "js" extension ( Note : do not write your functions in the external file between <script> .... </script>, it's no need to do that for an external file).
    Then you can call that file in any html file that you like by typing:

    <script language="javascript" src="TheNameOfFile.js">
    </script>

    Notice that when you use a <script> tag for reading an external file, you shouldn't put any other statements between that tag and it's closing ( </script> ) tag.

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Notice that when you use a <script> tag for reading an external file, you shouldn't put any other statements between that tag and it's closing ( </script> ) tag.
    It should also be noted that the file with the javascript in it should have no html in it. That means no <script> </script> tags, no <!-- --> comment tags or anything else. What it should contain is javascript, only javascript.

  • #4
    New to the CF scene
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Specific functioncall

    Thx for the quick responce!!

    I just have one question - maybe I'm a bit 'slow' but can't get it to work 100%

    I've done all you've mentioned so far, but how do I call a specific function?

    The way I did it is I've made different function with unique names etc, placed in that .js file. How do I then call e.g.
    Function validateDiz();

    from my html file? Is it
    <script language="javascript" src="MyFile.js">
    validateDiz();
    </script>

    or is it done in another way??

    Once again - thx for fast responce!

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's the proper syntax I believe:

    <script language="javascript" type="text/javascript" src="MyFile.js"></script>
    <script language="javascript" type="text/javascript">
    validateDiz();
    </script>


  •  

    Posting Permissions

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