Can't get Function to run from Include file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Bassett

    Can't get Function to run from Include file

    I have a .shtml file, that displays photos, in which I wish to pass some
    functionality off to an Include file for reusability purposes.
    Unfortunately, it's not working.

    Here is a portion of the .shtml file:

    ======
    <!--#include file="/tmb8/functions.inc"-->
    <script type="text/javascript">
    var title = "Noosa, Australia - October / November 2003"
    ..
    ..
    ..
    displayphotos(p hotoarray, args, photosinarow)
    ======

    Here is functions.inc:

    ========
    <%
    function displayphotos(p hotoarray, args, photosinarow)
    document.write( "hello, world<br>")
    end function
    %>
    ==========

    To start, I just want to see Hello, World but I just get nothing - the page
    is at http://www.solotraveller.com/tmb8/tm...03/index.shtml

    I think I'm putting the #include statement in the wrong place.
    I have been able to get functions to work earlier, but they were called
    from .asp files, not .shtml files.
  • Juliette

    #2
    Re: Can't get Function to run from Include file

    Peter Bassett wrote:[color=blue]
    >
    > I have a .shtml file, that displays photos, in which I wish to pass some
    > functionality off to an Include file for reusability purposes.
    > Unfortunately, it's not working.
    >
    > Here is a portion of the .shtml file:
    >
    > ======
    > <!--#include file="/tmb8/functions.inc"-->
    > <script type="text/javascript">
    > var title = "Noosa, Australia - October / November 2003"
    > .
    > .
    > .
    > displayphotos(p hotoarray, args, photosinarow)
    > ======
    >
    > Here is functions.inc:
    >
    > ========
    > <%
    > function displayphotos(p hotoarray, args, photosinarow)
    > document.write( "hello, world<br>")
    > end function
    > %>
    > ==========
    >
    > To start, I just want to see Hello, World but I just get nothing - the page
    > is at http://www.solotraveller.com/tmb8/tm...03/index.shtml
    >
    > I think I'm putting the #include statement in the wrong place.
    > I have been able to get functions to work earlier, but they were called
    > from .asp files, not .shtml files.[/color]


    Syntax problem:

    For inline (i.e. included in a HTML document) javascript functions to
    work the syntax should be:

    <SCRIPT TYPE="text/javascript" LANGUAGE="javas cript">
    function displayphotos(p hotoarray, args, photosinarow) {
    document.write( 'hello, world<br>');
    }
    </SCRIPT>

    Gr, Juliette

    Comment

    • David Dorward

      #3
      Re: Can't get Function to run from Include file

      Peter Bassett wrote:
      [color=blue]
      > <!--#include file="/tmb8/functions.inc"-->[/color]

      This is executed on the server
      [color=blue]
      > <script type="text/javascript">
      > displayphotos(p hotoarray, args, photosinarow)[/color]

      This is executed on the client
      [color=blue]
      > Here is functions.inc:
      > <%
      > function displayphotos(p hotoarray, args, photosinarow)
      > document.write( "hello, world<br>")
      > end function
      > %>[/color]

      This is executed on the server.

      You can not call a function in the server environment using client side
      scripting. You have to make a new request to the server, typically using a
      form or a link.

      --
      David Dorward http://dorward.me.uk/

      Comment

      • Michael Winter

        #4
        Re: Can't get Function to run from Include file

        Juliette wrote on 16 Nov 2003:

        <snip>
        [color=blue]
        > For inline (i.e. included in a HTML document) javascript
        > functions to work the syntax should be:
        >
        > <SCRIPT TYPE="text/javascript" LANGUAGE="javas cript">[/color]

        That is incorrect. The 'language' attribute has been deprecated for
        almost five years. It should not be used. Although this is irrelevant
        (do to my previous statement), the language attribute should include
        the version of JavaScript that the SCRIPT block contains. Specifying
        "JavaScript " indicates that JavaScript v1.0 objects, methods and
        statements follow (and this is probably not the case).

        One last point. You also neglected to wrap the JavaScript code in
        HTML comments (<!--...-->).

        Mike

        --
        Michael Winter
        M.Winter@[no-spam]blueyonder.co.u k (remove [no-spam] to reply)

        Comment

        • HikksNotAtHome

          #5
          Re: Can't get Function to run from Include file

          In article <Xns9436742C0B1 E5MWinterBlueyo nder@193.38.113 .46>, Michael Winter
          <M.Winter@[no-spam]blueyonder.co.u k> writes:
          [color=blue][color=green]
          >> <SCRIPT TYPE="text/javascript" LANGUAGE="javas cript">[/color]
          >
          >That is incorrect. The 'language' attribute has been deprecated for
          >almost five years. It should not be used. Although this is irrelevant
          >(do to my previous statement), the language attribute should include
          >the version of JavaScript that the SCRIPT block contains. Specifying
          >"JavaScript " indicates that JavaScript v1.0 objects, methods and
          >statements follow (and this is probably not the case).[/color]

          First, you say "language attribute is deprecated" and then you say that the
          "language attribute should include the version...". How do you include the
          version if you don't use the "deprecated language attribute"?

          <script type="text/javascript">

          Is sufficient.
          [color=blue]
          >One last point. You also neglected to wrap the JavaScript code in
          >HTML comments (<!--...-->).[/color]

          1) The language is javascript, to capitalize it JavaScript implies that its a
          Script for Java, which is very much *not* the case.

          2) They are not "HTML Comments" in an HTML document.

          3) If used, they are <!-- and //-->, not --> (even though a few of the modern
          browsers accept the improper -->, it was started as //-->)

          4) They are *not* needed in an HTML document. The browsers that can not handle
          javascript code without them are long out of use.
          --
          Randy

          Comment

          • Lasse Reichstein Nielsen

            #6
            Re: Can't get Function to run from Include file

            Michael Winter <M.Winter@[no-spam]blueyonder.co.u k> writes:
            [color=blue][color=green]
            >> <SCRIPT TYPE="text/javascript" LANGUAGE="javas cript">[/color]
            >
            > That is incorrect.[/color]

            It is not.
            [color=blue]
            > The 'language' attribute has been deprecated for almost five
            > years.[/color]

            It has, but that does not make it "incorrect" , just deprecated (unless
            you use a strict DTD, where it is incorrect).
            [color=blue]
            > It should not be used.[/color]

            I agree, but it is a recommendation, not a rule. Code containing it
            will still validate as HTML 4.01 Transitional.
            [color=blue]
            > Although this is irrelevant (do to my previous statement), the
            > language attribute should include the version of JavaScript that the
            > SCRIPT block contains. Specifying "JavaScript " indicates that
            > JavaScript v1.0 objects, methods and statements follow (and this is
            > probably not the case).[/color]

            Can you give a reference for this claim? I believe writing
            "JavaScript " with no version number would give the most recent
            Javsacript version sipported by the client.

            From the Netscape 4 HTML manual:
            ---
            LANGUAGE="langu ageName"
            specifies the program language. If the LANGUAGE attribute is not
            specified, the default value is JavaScript.

            You can specify JavaScript 1.1 for scripts to be executed by the 1.1
            version of JavaScript (compatible with Navigator 3.0) or JavaScript
            1.0 for scripts to be executed by the 1.0 version. *Navigator 3.0*
            ---
            Since Netscape 4 supported JavaScript 1.2 (and later 1.3), I would have
            expected them to say that you could write Javascript1.2 for that version.
            They don't, leading me to believe that that is the default.

            That is, 'language="Java script"' is not specifying the version,
            leaving that to the browser, and it is not specifying version 1.0.

            What *is* bad is people writing language="javas cript1.2" without
            knowing the differences between that and later Javascript versions
            (Javascript 1.2 was only present in Netscape navigator 4.0 - 4.05,
            then they changed some of the new features back and became ECMA 262
            compatible).
            [color=blue]
            > One last point. You also neglected to wrap the JavaScript code in
            > HTML comments (<!--...-->).[/color]

            Keep it up. They are not needed, unless you are targeting browsers
            from before 1997 (Netscape 1, IE 2, Opera 1). It is also a bad habit
            to get, since in XHTML, it will actually remove the script.

            /L
            --
            Lasse Reichstein Nielsen - lrn@hotpop.com
            DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
            'Faith without judgement merely degrades the spirit divine.'

            Comment

            • Michael Winter

              #7
              Re: Can't get Function to run from Include file

              HikksNotAtHome wrote on 17 Nov 2003:
              [color=blue]
              > In article <Xns9436742C0B1 E5MWinterBlueyo nder@193.38.113 .46>,
              > Michael Winter <M.Winter@[no-spam]blueyonder.co.u k> writes:
              >[color=green][color=darkred]
              >>> <SCRIPT TYPE="text/javascript" LANGUAGE="javas cript">[/color]
              >>
              >>That is incorrect. The 'language' attribute has been deprecated
              >>for almost five years. It should not be used. Although this is
              >>irrelevant (do to my previous statement), the language attribute
              >>should include the version of JavaScript that the SCRIPT block
              >>contains. Specifying "JavaScript " indicates that JavaScript v1.0
              >>objects, methods and statements follow (and this is probably not
              >>the case).[/color]
              >
              > First, you say "language attribute is deprecated" and then you
              > say that the "language attribute should include the version...".
              > How do you include the version if you don't use the "deprecated
              > language attribute"?[/color]

              I said: "Although this is irrelevant (do to my previous
              statement)...". The previous statement was that 'language' is
              deprecated.

              If you don't specify 'language' (i.e. only 'type'), the browser
              should, based on browser/language version comparisons, default to the
              latest version of the language it supports.
              [color=blue]
              > <script type="text/javascript">
              >
              > Is sufficient.
              >[color=green]
              >>One last point. You also neglected to wrap the JavaScript code
              >>in HTML comments (<!--...-->).[/color]
              >
              > 1) The language is javascript, to capitalize it JavaScript
              > implies that its a Script for Java, which is very much *not* the
              > case.[/color]

              Netscape's own language guide and reference capitalises the language
              in that manner, and Netscape created the language.
              [color=blue]
              > 2) They are not "HTML Comments" in an HTML document.[/color]

              I was distinguishing them from JavaScript comments.
              [color=blue]
              > 3) If used, they are <!-- and //-->, not --> (even though a few
              > of the modern browsers accept the improper -->, it was started
              > as //-->)[/color]

              It was to indicate further that I was referring to comments used in
              HTML documents, rather than JavaScript comments.
              [color=blue]
              > 4) They are *not* needed in an HTML document. The browsers that
              > can not handle javascript code without them are long out of use.[/color]

              1) Can you *guarantee* that?
              2) It doesn't adversely affect the content of the script or the HTML
              document, does it?

              Mike

              --
              Michael Winter
              M.Winter@[no-spam]blueyonder.co.u k (remove [no-spam] to reply)

              Comment

              • Fabian

                #8
                Re: Can't get Function to run from Include file

                Michael Winter hu kiteb:

                [color=blue]
                > One last point. You also neglected to wrap the JavaScript code in
                > HTML comments (<!--...-->).[/color]

                Others o this group have noted that if you are using a browser that has
                teh language attribute deprecated, that browser would also not need the
                script commented out. Therefore, I can only assume that (<!--...-->) is
                actually one of teh more obscure Japanese smilies (~-~)


                --
                --
                Fabian
                Visit my website often and for long periods!


                Comment

                • Lasse Reichstein Nielsen

                  #9
                  Re: Can't get Function to run from Include file

                  Michael Winter <M.Winter@[no-spam]blueyonder.co.u k> writes:
                  [color=blue]
                  > Netscape's own language guide and reference capitalises the language
                  > in that manner, and Netscape created the language.[/color]

                  Yes. I would accept any (sub-)capitalization of Javascript, although
                  as a proper noun, I would expect the first letter to be capitalized.
                  [color=blue][color=green]
                  >> 4) They are *not* needed in an HTML document. The browsers that
                  >> can not handle javascript code without them are long out of use.[/color]
                  >
                  > 1) Can you *guarantee* that?[/color]

                  Any browser that understands HTML 3, or that understands the script tag
                  at all, will not need HTML-like comments (actually, to those browsers,
                  it *would* be HTML comments).

                  Can I guarantee that nobody uses a browser so old that it doesn't know
                  what the script tag is? No.

                  If you check www.thecounter. com's browser statistics, they logged
                  72 accesses by Netscape 1, 21 by MSIE 1 and 11154 by MSIE 2. Those
                  browsers would need HTML comments. That was out of 38 million accesses,
                  a whooping 0.03 percent.

                  Then add the likelyhood of these being either falsified userAgent
                  strings or people using the browsers for testing only (compared to the
                  unlikely possibility of people actually using these browsers and
                  disguising them as other browsers)

                  If you otherwise support these browsers, then I would also worry about
                  the HTML comments. Otherwise, I wouldn't.
                  [color=blue]
                  > 2) It doesn't adversely affect the content of the script or the HTML
                  > document, does it?[/color]

                  No. But I wouldn't say that omitting them does any harm either. I
                  definitly would't tell someone to put them in if they omitted them.


                  Personally, I think it is a bad habit, bordering on voodoo ("I put it
                  here because I think it makes a difference, but I don't know how"),
                  and I would like it stopped.

                  /L
                  --
                  Lasse Reichstein Nielsen - lrn@hotpop.com
                  DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                  'Faith without judgement merely degrades the spirit divine.'

                  Comment

                  • Michael Winter

                    #10
                    Re: Can't get Function to run from Include file

                    Lasse Reichstein Nielsen wrote on 17 Nov 2003:
                    [color=blue]
                    > Michael Winter <M.Winter@[no-spam]blueyonder.co.u k> writes:
                    >[color=green][color=darkred]
                    >>> <SCRIPT TYPE="text/javascript" LANGUAGE="javas cript">[/color]
                    >>
                    >> That is incorrect.[/color]
                    >
                    > It is not.
                    >[color=green]
                    >> The 'language' attribute has been deprecated for almost five
                    >> years.[/color]
                    >
                    > It has, but that does not make it "incorrect" , just deprecated
                    > (unless you use a strict DTD, where it is incorrect).
                    >[color=green]
                    >> It should not be used.[/color]
                    >
                    > I agree, but it is a recommendation, not a rule. Code containing
                    > it will still validate as HTML 4.01 Transitional.[/color]

                    True, but there is little reason to continue using the Transitional
                    DTD. The only reason I can see why browsers continue to support it is
                    due to the large number of 'legacy' websites that still use it. Why
                    bother adding to that list? The only attribute that I've ever wanted
                    from it is the 'target' attribute for use with tables. However, that
                    can avoided with JavaScript, and if JavaScript is not supported by a
                    client, a "no tables" layout can be used instead.
                    [color=blue][color=green]
                    >> Although this is irrelevant (do to my previous statement), the
                    >> language attribute should include the version of JavaScript
                    >> that the SCRIPT block contains. Specifying "JavaScript "
                    >> indicates that JavaScript v1.0 objects, methods and statements
                    >> follow (and this is probably not the case).[/color]
                    >
                    > Can you give a reference for this claim? I believe writing
                    > "JavaScript " with no version number would give the most recent
                    > Javsacript version sipported by the client.
                    >
                    > From the Netscape 4 HTML manual:
                    > ---
                    > LANGUAGE="langu ageName"
                    > specifies the program language. If the LANGUAGE attribute is
                    > not specified, the default value is JavaScript.[/color]

                    According to the Transitional DTD, the 'language' attribute is
                    defined by the user agent when not present. So, it is possible that
                    later browsers may use other values.
                    [color=blue]
                    > You can specify JavaScript 1.1 for scripts to be executed by
                    > the 1.1 version of JavaScript (compatible with Navigator 3.0)
                    > or JavaScript 1.0 for scripts to be executed by the 1.0
                    > version. *Navigator 3.0*
                    > ---
                    > Since Netscape 4 supported JavaScript 1.2 (and later 1.3), I
                    > would have expected them to say that you could write
                    > Javascript1.2 for that version. They don't, leading me to
                    > believe that that is the default.
                    >
                    > That is, 'language="Java script"' is not specifying the version,
                    > leaving that to the browser, and it is not specifying version
                    > 1.0.
                    >
                    > What *is* bad is people writing language="javas cript1.2" without
                    > knowing the differences between that and later Javascript
                    > versions (Javascript 1.2 was only present in Netscape navigator
                    > 4.0 - 4.05, then they changed some of the new features back and
                    > became ECMA 262 compatible).[/color]

                    There is a table in the Client-Side JavaScript Guide (v1.3, Chapter 9
                    - Specifying the JavaScript Version) that shows what 'language'
                    values are supported by which NN versions.

                    The value 'JavaScript' is used with v1.0 and 'JavaScript1.?'
                    thereafter. In the table, 'JavaScript' is treated as an earlier
                    version compared to strings that specify a version number.

                    This is the table. The "Tags supported" column is verbatim - the
                    other columns are abbreviated to prevent too much wrapping.

                    NN ver. JS ver. Tags supported

                    <2.0 none n/a
                    2.0 1.0 <SCRIPT LANGUAGE="JavaS cript">
                    3.0 1.1 <SCRIPT LANGUAGE="JavaS cript1.1"> and all earlier
                    versions
                    4.0-.05 1.2 <SCRIPT LANGUAGE="JavaS cript1.2"> and all earlier
                    versions
                    4.06-.5 1.3 <SCRIPT LANGUAGE="JavaS cript1.3"> and all earlier
                    versions
                    [color=blue][color=green]
                    >> One last point. You also neglected to wrap the JavaScript code
                    >> in HTML comments (<!--...-->).[/color]
                    >
                    > Keep it up. They are not needed, unless you are targeting
                    > browsers from before 1997 (Netscape 1, IE 2, Opera 1). It is
                    > also a bad habit to get, since in XHTML, it will actually remove
                    > the script.[/color]

                    Interesting point, but I don't write using XHTML, and if I did, I'd
                    quickly notice that JavaScript code isn't being executed.

                    Mike

                    --
                    Michael Winter
                    M.Winter@[no-spam]blueyonder.co.u k

                    Comment

                    • Lasse Reichstein Nielsen

                      #11
                      Re: Can't get Function to run from Include file

                      Michael Winter <M.Winter@[no-spam]blueyonder.co.u k> writes:
                      [color=blue]
                      > True, but there is little reason to continue using the Transitional
                      > DTD.[/color]

                      Little reason, yes, and I don't myself, but it is still *correct*.
                      [color=blue]
                      > The only reason I can see why browsers continue to support it is
                      > due to the large number of 'legacy' websites that still use it.[/color]

                      Hardly. That is the reason why they support tag soup parsing.
                      I have yet to see a browser that honors the DOCTYPE declaration to the
                      point where they refuse features not in the chosen document type. They
                      might separate between HTML and XHTML, but that is it.
                      [color=blue]
                      > Why bother adding to that list?[/color]

                      Some people would claim that XHTML is the future of the web, and people
                      using HTML are holding us back. You are adding to their list.

                      It is all a matter of perspective.

                      I am satisfied if somebody else's page validates. That is far better
                      than the prevailing mindset: "as long as it works" (for some definition
                      of "works" that mostly refer to IE).
                      [color=blue]
                      > The only attribute that I've ever wanted from it is the 'target'
                      > attribute for use with tables. However, that can avoided with
                      > JavaScript, and if JavaScript is not supported by a client, a "no
                      > tables" layout can be used instead.[/color]

                      I guess you mean "no frames".
                      [color=blue][color=green]
                      >> Can you give a reference for this claim?[/color][/color]
                      ....[color=blue]
                      > There is a table in the Client-Side JavaScript Guide (v1.3, Chapter 9
                      > - Specifying the JavaScript Version) that shows what 'language'
                      > values are supported by which NN versions.[/color]

                      Thanks, reference accepted.

                      All the more reason to not use the language attribute. And it only
                      refer to the Netscape browser. Except for Mozilla, I don't believe
                      other browsers respect the version number, since they only have one
                      Javascript engine available (e.g. JScript through the WSH).

                      /L
                      --
                      Lasse Reichstein Nielsen - lrn@hotpop.com
                      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                      'Faith without judgement merely degrades the spirit divine.'

                      Comment

                      • Michael Winter

                        #12
                        Re: Can't get Function to run from Include file

                        Lasse Reichstein Nielsen wrote on 17 Nov 2003:

                        <snip>
                        [color=blue]
                        > Any browser that understands HTML 3, or that understands the
                        > script tag at all, will not need HTML-like comments (actually,
                        > to those browsers, it *would* be HTML comments).
                        >
                        > Can I guarantee that nobody uses a browser so old that it
                        > doesn't know what the script tag is? No.
                        >
                        > If you check www.thecounter. com's browser statistics, they
                        > logged 72 accesses by Netscape 1, 21 by MSIE 1 and 11154 by MSIE
                        > 2. Those browsers would need HTML comments. That was out of 38
                        > million accesses, a whooping 0.03 percent.
                        >
                        > Then add the likelyhood of these being either falsified
                        > userAgent strings or people using the browsers for testing only
                        > (compared to the unlikely possibility of people actually using
                        > these browsers and disguising them as other browsers)
                        >
                        > If you otherwise support these browsers, then I would also worry
                        > about the HTML comments. Otherwise, I wouldn't.[/color]

                        <snip>
                        [color=blue]
                        > No. But I wouldn't say that omitting them does any harm either.
                        > I definitly would't tell someone to put them in if they omitted
                        > them.
                        >
                        > Personally, I think it is a bad habit, bordering on voodoo ("I
                        > put it here because I think it makes a difference, but I don't
                        > know how"), and I would like it stopped.[/color]

                        The problem with legacy support is clearly: where to draw the line.
                        It would appear that hiding scripts from old browsers is one such
                        place.

                        Mike

                        --
                        Michael Winter
                        M.Winter@[no-spam]blueyonder.co.u k

                        Comment

                        • GIMME

                          #13
                          Re: Can't get Function to run from Include file

                          > > For inline (i.e. included in a HTML document) javascript[color=blue][color=green]
                          > > functions to work the syntax should be:
                          > >
                          > > <SCRIPT TYPE="text/javascript" LANGUAGE="javas cript">[/color][/color]

                          Wrong. You need an end-script tag , as in </script>

                          Comment

                          • GIMME

                            #14
                            Re: Can't get Function to run from Include file

                            > <!--#include file="/tmb8/functions.inc"-->

                            This is an apache server side include ...

                            Your server has to be configured to support it.

                            By default it is not supported.

                            Comment

                            • Thomas 'PointedEars' Lahn

                              #15
                              Re: Can't get Function to run from Include file

                              Lasse Reichstein Nielsen wrote:
                              [color=blue]
                              > Michael Winter <M.Winter@[no-spam]blueyonder.co.u k> writes:
                              > I have yet to see a browser that honors the DOCTYPE declaration to the
                              > point where they refuse features not in the chosen document type. They
                              > might separate between HTML and XHTML, but that is it.[/color]

                              Take Mozilla/5.0 and an XHTML DOCTYPE (or one of any other XML
                              application). It does not even matter if XHTML it is served
                              (correctly) as application/xhtml+xml. You are right for HTML
                              DOCTYPES, though, because both Mozilla/5.0 and IE then switch
                              to Quirks Mode.


                              PointedEars

                              Comment

                              Working...