newbie: problem with calling or including .js file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • r_ahimsa_m@poczta.onet.pl

    newbie: problem with calling or including .js file

    Hello,
    I am learning WWW technologies in Linux. I created index.html file which I
    can browse with Firefox/Konqueror using URL
    localhost/~robert/rozgloszenia/index.html. The page looks fine but there's
    one strange problem: I have written some JavaScript code in functions.js
    file which seems to be ignored when called although I have JavaScript
    enabled in Firefox/Konqueror.

    For example in functions.js I have:

    function getCurrentYear( )
    {
    var today = Date();
    return today.getFullYe ar();
    }

    I have written:

    <head>
    ...
    <script src="functions. js" language="javas cript"
    type="text/javascript"></script>
    </head>

    and then I have:

    <script language="javas cript"
    type="text/javascript">doc ument.write(get CurrentDate()); </script>

    There's nothing in oputput.

    When I have written simple line:

    <script language="javas cript"
    type="text/javascript">doc ument.write('AB C');</script>

    output is correct (ABC characters).
    But when I put document.write( 'ABC'); in Test() function in functions.js and
    call it:

    <script language="javas cript" type="text/javascript">Tes t();</script>

    then there's nothing in output.

    The file functions.js has -rw-rw-r-- priviledges.

    Please help.
    Thanks in advance.
    /RAM/
  • Steve

    #2
    Re: newbie: problem with calling or including .js file

    On Jun 13, 11:09 am, r_ahims...@pocz ta.onet.pl wrote:
    Hello,
    I am learning WWW technologies in Linux. I created index.html file which I
    can browse with Firefox/Konqueror using URL
    localhost/~robert/rozgloszenia/index.html. The page looks fine but there's
    one strange problem: I have written some JavaScript code in functions.js
    file which seems to be ignored when called although I have JavaScript
    enabled in Firefox/Konqueror.
    >
    For example in functions.js I have:
    >
    function getCurrentYear( )
    {
    var today = Date();
    return today.getFullYe ar();
    >
    }
    >
    I have written:
    >
    <head>
    ...
    <script src="functions. js" language="javas cript"
    type="text/javascript"></script>
    </head>
    >
    and then I have:
    >
    <script language="javas cript"
    type="text/javascript">doc ument.write(get CurrentDate()); </script>
    >
    There's nothing in oputput.
    >
    When I have written simple line:
    >
    <script language="javas cript"
    type="text/javascript">doc ument.write('AB C');</script>
    >
    output is correct (ABC characters).
    But when I put document.write( 'ABC'); in Test() function in functions.js and
    call it:
    >
    <script language="javas cript" type="text/javascript">Tes t();</script>
    >
    then there's nothing in output.
    >
    The file functions.js has -rw-rw-r-- priviledges.
    >
    Please help.
    Thanks in advance.
    /RAM/
    Hi,

    I am also a Linux user and have found out that most users of this
    newsgroup are not. The people here are usually very helpful but you
    need to first identify whether you have a Linux problem, for instance
    a permissions problem, or a HTML/Javascript problem.

    The easiest way to do this would be to post your index.html and
    functions.js files on a server where the newsgroup users can access
    them with their own browsers. If the problem is a Javasript (or HTML)
    problem they will help you.

    Regards,

    Steve.

    Comment

    • SAM

      #3
      Re: newbie: problem with calling or including .js file

      r_ahimsa_m@pocz ta.onet.pl a écrit :
      Hello,
      I am learning WWW technologies in Linux. I created index.html file which I
      can browse with Firefox/Konqueror using URL
      localhost/~robert/getCurrentYear/index.html. The page looks fine but there's
      one strange problem: I have written some JavaScript code in functions.js
      file which seems to be ignored when called although I have JavaScript
      enabled in Firefox/Konqueror.
      and calling the file by :
      file://localhost/Users/robert/getCurrentYear/index.html
      or something like that
      (to see if it's really a pb of privileges)
      For example in functions.js I have:
      >
      function getCurrentYear( )
      {
      var today = Date();
      return today.getFullYe ar();
      }
      >
      I have written:
      >
      <head>
      ...
      <script src="functions. js" language="javas cript"
      type="text/javascript"></script>
      </head>
      >
      and then I have:
      >
      <script language="javas cript"
      type="text/javascript">doc ument.write(get CurrentDate()); </script>
      could be better with : document.write( getCurrentYear( ));
      no ?

      --
      sm

      Comment

      • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

        #4
        Re: newbie: problem with calling or including .js file

        r_ahimsa_m@pocz ta.onet.pl escribió:
        localhost/~robert/rozgloszenia/index.html. The page looks fine but there's
        one strange problem: I have written some JavaScript code in functions.js
        file which seems to be ignored when called although I have JavaScript
        enabled in Firefox/Konqueror.
        Debugging steps you can take:

        1. Check your web server's logs: is the *.js file actually requested? Is
        it served successfully?

        2. Check Firefox's JavaScript console (Tools menu)

        3. Get the Firebug extension for Firefox.
        <script src="functions. js" language="javas cript"
        type="text/javascript"></script>
        BTW, the language attribute is deprecated. I suppose you don't validate
        your HTML with W3C validator: you should. Extensions like Web Developer
        Toolbar for Firefox can help you to validate local HTML or you can just
        paste or upload the file:

        W3C's easy-to-use markup validation service, based on SGML and XML parsers.



        --
        -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
        -- Mi sitio sobre programación web: http://bits.demogracia.com
        -- Mi web de humor al baño María: http://www.demogracia.com
        --

        Comment

        • Tom Cole

          #5
          Re: newbie: problem with calling or including .js file

          On Jun 13, 7:15 am, "Álvaro G. Vicario"
          <alvaroNOSPAMTH A...@demogracia .comwrote:
          r_ahims...@pocz ta.onet.pl escribió:
          >
          localhost/~robert/rozgloszenia/index.html. The page looks fine but there's
          one strange problem: I have written some JavaScript code in functions.js
          file which seems to be ignored when called although I have JavaScript
          enabled in Firefox/Konqueror.
          >
          Debugging steps you can take:
          >
          1. Check your web server's logs: is the *.js file actually requested? Is
          it served successfully?
          >
          2. Check Firefox's JavaScript console (Tools menu)
          >
          3. Get the Firebug extension for Firefox.
          >
                  <script src="functions. js" language="javas cript"
          type="text/javascript"></script>
          >
          BTW, the language attribute is deprecated. I suppose you don't validate
          your HTML with W3C validator: you should. Extensions like Web Developer
          Toolbar for Firefox can help you to validate local HTML or you can just
          paste or upload the file:
          >
          W3C's easy-to-use markup validation service, based on SGML and XML parsers.

          >
          --
          --http://alvaro.es- Álvaro G. Vicario - Burgos, Spain
          -- Mi sitio sobre programación web:http://bits.demogracia.com
          -- Mi web de humor al baño María:http://www.demogracia.com
          --
          I also notice that your function defined in the .js file is named
          getCurrentYear, yet the one you're attempting to call is
          getCurrentDate. ..

          Do you have Firebug or Venkeman installed on your Firefox
          installation? It would show if there were any javascript errors.

          Comment

          Working...