Include .js file inside HTML and call functions from another <script>

Discussion in 'Javascript' started by Iddo, Apr 5, 2006.

  1. Iddo

    Iddo Guest

    Hi,
    I am having a strange problem...
    I have an HTML file which has 2 script tags:
    1) <script language="javascript" id="ABC" src="ABC.js" />
    2) <script id="general" language="javascript">
    function foo()
    {
    alert("aaa");
    }
    </script>

    I am trying to call the "foo" function and also functions from the
    "ABC.js" file.

    when calling the ".js" file - functions are called fine!
    however, when calling the "foo" function - I get an error! ("Object
    expected")

    My HTML:
    <HTML>
    <head>
    <script language="javascript" id="ABC" src="ABC.js" />
    <script id="general" language="javascript">
    function foo()
    {
    alert("aaa");
    }
    </script>
    <title>Test</title>
    </head>
    <body>
    <INPUT id="Button1" type="button" value="JS1"
    onclick="JSFileFunction()"></P>
    <INPUT id="Button2" type="button" value="JS2" onclick="foo()"></P>
    </body>
    </HTML>

    My ABC.js file:
    function JSFileFunction()
    {
    alert("ABC");
    }


    PLZ help me.... I'm stuck!!!
    Iddo, Apr 5, 2006
    #1
    1. Advertising

  2. Iddo

    VK Guest

    Iddo wrote:
    > Hi,
    > I am having a strange problem...
    > I have an HTML file which has 2 script tags:
    > 1) <script language="javascript" id="ABC" src="ABC.js" />
    > 2) <script id="general" language="javascript">
    > function foo()
    > {
    > alert("aaa");
    > }
    > </script>


    I have forgotten the closing tag for the external file (<script>
    elements always requires closing tag).

    Script element has type "text/javascript" (not language "javascript").

    Script elements doesn't have id attribute.

    <script type="text/javascript" src="ABC.js"></script>
    <script type="text/javascript">
    // your code here
    </script>
    VK, Apr 5, 2006
    #2
    1. Advertising

  3. Iddo

    Guest

    Change:
    <script language="javascript" id="ABC" src="ABC.js" />

    into
    <script language="javascript" id="ABC" src="ABC.js"></script>


    That solved the problem for me (in Firefox)
    , Apr 5, 2006
    #3
  4. Iddo wrote:

    > I have an HTML file which has 2 script tags:


    There are no "script tags". There are (script) _elements_,
    consisting of start and end tag, and optionally content.

    > 1) <script language="javascript" id="ABC" src="ABC.js" />


    MUST be at least

    <script type="text/javascript" language="javascript"
    src="ABC.js"></script>

    HTML's SHORTTAG syntax is different from XHTML's. In HTML,

    <script ... />

    is equivalent to

    <script ...>&gt;

    First, text content is not allowed directly below the `head' element,
    and second, the `script' element is not closed.

    > 2) <script id="general" language="javascript">


    Must be at least

    <script type="text/javascript" language="javascript">

    The `type' attribute is mandatory, and the element has no `id' attribute
    (nor would it need one). The `language' attribute is deprecated in HTML
    4.01, and can be safely omitted. It MUST be omitted if you declare HTML
    4.01 Strict.

    > [...]
    > I am trying to call the "foo" function and also functions from the
    > "ABC.js" file.
    > when calling the ".js" file


    Files cannot be called, they can be executed if they contain executable
    code. But this is no file, it is a script resource (that can be saved
    as a file). It can be (down)loaded, if that.

    > - functions are called fine!
    > however, when calling the "foo" function - I get an error! ("Object
    > expected")


    It would appear that due to forced error-correction of your invalid markup,
    the </script> (close) tag of the second `script' element is understood as
    the close tag for the first `script' element, and any code in the second
    `script' element is ignored. Hence there is no foo() method that can be
    called.

    > <HTML>


    Although not required in HTML, element type identifiers and attribute
    identifiers should be lowercase always. A DOCTYPE declaration is missing
    before this start tag of the `html' element.

    > <INPUT id="Button1" type="button" value="JS1"
    > onclick="JSFileFunction()"></P>
    > <INPUT id="Button2" type="button" value="JS2" onclick="foo()"></P>


    It does not seem as if you would need an ID for either button.
    There is no <P> open tag, so nothing that needs to be closed with </P>.

    <URL:http://validator.w3.org/>

    > PLZ help me.... I'm stuck!!!


    It would be best if you understood the basics of Web authoring before you
    started with Web programming.


    PointedEars
    Thomas 'PointedEars' Lahn, Apr 6, 2006
    #4
  5. In article <>, Thomas 'PointedEars'
    Lahn <> writes
    >Iddo wrote:


    <snip>
    >> <HTML>

    >
    >Although not required in HTML, element type identifiers and attribute
    >identifiers should be lowercase always.

    <snip>

    Why? Do you have a technical reason, or are you just being an art
    critic?

    John
    --
    John Harris
    John G Harris, Apr 6, 2006
    #5
  6. John G Harris wrote:

    > [...] Thomas 'PointedEars' Lahn [...] writes
    >>Iddo wrote:
    >>> <HTML>

    >>
    >> Although not required in HTML, element type identifiers and attribute
    >> identifiers should be lowercase always.

    >
    > Why? Do you have a technical reason, or are you just being an art
    > critic?


    Yes. It compresses better, is less error-prone, and is good to be developed
    as a habit when taking more recent markup languages into account.


    PointedEars
    Thomas 'PointedEars' Lahn, Apr 6, 2006
    #6
  7. Iddo

    Ivan Marsh Guest

    On Sat, 08 Apr 2006 00:57:16 +0200, Bruno Desthuilliers wrote:

    > Tony a écrit :
    >> Thomas 'PointedEars' Lahn wrote:
    >>> John G Harris wrote:
    >>>> [...] Thomas 'PointedEars' Lahn [...] writes
    >>>>>
    >>>>> Although not required in HTML, element type identifiers and attribute
    >>>>> identifiers should be lowercase always.
    >>>>
    >>>> Why? Do you have a technical reason, or are you just being an art
    >>>> critic?
    >>>
    >>> Yes. It compresses better, is less error-prone, and is good to be
    >>> developed
    >>> as a habit when taking more recent markup languages into account.

    >>
    >> Not sure how it would "compress better"

    >
    > Probably because most the text of a page being lowercase, you may have
    > better compression with tag names also in lowercase... (wild guess) (and
    > totally ot).


    Huh? In ASCII all characters are seven bit.


    --
    The USA Patriot Act is the most unpatriotic act in American history.
    Ivan Marsh, Apr 7, 2006
    #7
  8. Bruno Desthuilliers wrote:

    > Tony a écrit :
    >> Thomas 'PointedEars' Lahn wrote:
    >>> John G Harris wrote:
    >>>> [...] Thomas 'PointedEars' Lahn [...] writes
    >>>>> Although not required in HTML, element type identifiers and attribute
    >>>>> identifiers should be lowercase always.
    >>>> Why? Do you have a technical reason, or are you just being an art
    >>>> critic?
    >>> Yes. It compresses better, is less error-prone, and is good to be
    >>> developed as a habit when taking more recent markup languages into
    >>> account.

    >> Not sure how it would "compress better"

    >
    > Probably because most the text of a page being lowercase, you may have
    > better compression with tag names


    and attribute names (but not attribute values, of course)

    > also in lowercase... (wild guess)


    Exactly. Redundancy counts.

    > (and totally ot).


    ACK


    PointedEars
    Thomas 'PointedEars' Lahn, Apr 7, 2006
    #8
  9. Iddo

    Ivan Marsh Guest

    On Fri, 07 Apr 2006 22:27:21 +0200, Thomas 'PointedEars' Lahn wrote:

    > Bruno Desthuilliers wrote:
    >
    >> Tony a écrit :
    >>> Thomas 'PointedEars' Lahn wrote:
    >>>> John G Harris wrote:
    >>>>> [...] Thomas 'PointedEars' Lahn [...] writes
    >>>>>> Although not required in HTML, element type identifiers and attribute
    >>>>>> identifiers should be lowercase always.
    >>>>> Why? Do you have a technical reason, or are you just being an art
    >>>>> critic?
    >>>> Yes. It compresses better, is less error-prone, and is good to be
    >>>> developed as a habit when taking more recent markup languages into
    >>>> account.
    >>> Not sure how it would "compress better"

    >>
    >> Probably because most the text of a page being lowercase, you may have
    >> better compression with tag names

    >
    > and attribute names (but not attribute values, of course)
    >
    >> also in lowercase... (wild guess)

    >
    > Exactly. Redundancy counts.


    What compression utilizing redundancy occurs between the web server and
    the browser?

    --
    The USA Patriot Act is the most unpatriotic act in American history.
    Ivan Marsh, Apr 7, 2006
    #9
  10. Re: Include .js file inside HTML and call functions from another<script>

    Tony a écrit :
    > Thomas 'PointedEars' Lahn wrote:
    >
    >> John G Harris wrote:
    >>
    >>> [...] Thomas 'PointedEars' Lahn [...] writes
    >>>
    >>>>
    >>>> Although not required in HTML, element type identifiers and attribute
    >>>> identifiers should be lowercase always.
    >>>
    >>>
    >>> Why? Do you have a technical reason, or are you just being an art
    >>> critic?

    >>
    >>
    >> Yes. It compresses better, is less error-prone, and is good to be
    >> developed
    >> as a habit when taking more recent markup languages into account.

    >
    >
    > Not sure how it would "compress better"


    Probably because most the text of a page being lowercase, you may have
    better compression with tag names also in lowercase... (wild guess) (and
    totally ot).
    Bruno Desthuilliers, Apr 7, 2006
    #10
  11. Iddo

    VK Guest

    Ivan Marsh wrote:
    > Huh? In ASCII all characters are seven bit.


    Huh? The US may have some defaults, but not up to the point of using
    seven-bit bytes :)

    ASCII characters are the conventional 8-bit bytes, but only 7 bits are
    used, which brings the total amount of possible combinations to 127
    (low part of ASCII table).
    VK, Apr 8, 2006
    #11
  12. VK wrote:

    > Ivan Marsh wrote:
    >> Huh? In ASCII all characters are seven bit.

    >
    > Huh? The US may have some defaults, but not up to the point of using
    > seven-bit bytes :)


    And even if they had, the statement would be irrelevant regarding data
    compression. For it was not argued that a lowercase character required
    less bits to be encoded (on the contrary, if ASCII was not the fixed-width
    encoding that it is, lowercase characters would require _more_ bits to be
    encoded than uppercase characters, because uppercase characters have
    _lower_ code points than lowercase characters in ASCII).

    > ASCII characters are the conventional 8-bit bytes, but only 7 bits are
    > used,


    False. The eighth bit has been (is?) used, too, but not for the character
    code.

    > which brings the total amount of possible combinations to 127
    > (low part of ASCII table).


    False. The number is 2^7 = 128, of course. From 0 to 127 decimal
    (7F hexadecimal).

    <URL:http://en.wikipedia.org/wiki/ASCII>


    PointedEars
    Thomas 'PointedEars' Lahn, Apr 8, 2006
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nail
    Replies:
    0
    Views:
    1,537
  2. Tom
    Replies:
    8
    Views:
    665
    Adrienne Boswell
    Feb 13, 2007
  3. beginner
    Replies:
    7
    Views:
    546
    Alex Martelli
    Aug 19, 2007
  4. Andreas Bogenberger
    Replies:
    3
    Views:
    899
    Andreas Bogenberger
    Feb 22, 2008
  5. Kent

    Include a html file inside an aspx file

    Kent, Jan 15, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    417
    Alessandro Zifiglio
    Jan 16, 2004
Loading...

Share This Page