external .js page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Trevor Stapleton

    #1

    external .js page

    Hi i am new to javascript, (two weeks ) I have some programming
    experience, this is what i want to do.

    I have a small script (it prints the date in the UK fashion ) that i
    want to include on several but not all the pages on my web site.
    it seems illogical to type all the code on every page, I understand I
    can put the code in a file lets call it do_date.js and have it used by
    the pages it is needed on, i just don't seem to be able to get it to
    work, suggestions would be most welcome>
    Trev
  • Juliette

    #2
    Re: external .js page

    Trevor Stapleton wrote:[color=blue]
    >
    > Hi i am new to javascript, (two weeks ) I have some programming
    > experience, this is what i want to do.
    >
    > I have a small script (it prints the date in the UK fashion ) that i
    > want to include on several but not all the pages on my web site.
    > it seems illogical to type all the code on every page, I understand I
    > can put the code in a file lets call it do_date.js and have it used by
    > the pages it is needed on, i just don't seem to be able to get it to
    > work, suggestions would be most welcome>
    > Trev[/color]

    Trev,

    As a newbie, you'd do good to read the FAQ of this newsgroup....:


    But just to help you on your way (code presumes you put your js include
    files in a seperate directory called "include"):

    If you wrap the code in a function, include the following in the <HEAD>
    of each HTML doc:
    <SCRIPT TYPE="text/javascript" LANGUAGE="JavaS cript"
    SRC="include/do_date.js"></SCRIPT>

    In the <BODY> of each HTML doc in the location where you want the
    snippet to show, put:
    <SCRIPT TYPE="text/javascript"
    LANGUAGE="JavaS cript">function name();</SCRIPT>

    If you don't wrap the code in a function, you can leave the bit in the
    <HEAD> and just add the following in the HTML document at the right
    place :
    <SCRIPT TYPE="text/javascript" LANGUAGE="JavaS cript"
    SRC="include/do_date.js"></SCRIPT>

    Good luck, Juliette

    Comment

    • Cardman

      #3
      Re: external .js page

      On Sat, 31 Jan 2004 23:14:39 +0000, Trevor Stapleton
      <trevor.staplet on@ntlworld.com > wrote:
      [color=blue]
      >Hi i am new to javascript, (two weeks ) I have some programming
      >experience, this is what i want to do.
      >
      >I have a small script (it prints the date in the UK fashion ) that i
      >want to include on several but not all the pages on my web site.
      >it seems illogical to type all the code on every page, I understand I
      >can put the code in a file lets call it do_date.js and have it used by
      >the pages it is needed on, i just don't seem to be able to get it to
      >work, suggestions would be most welcome>
      >Trev[/color]

      My sites happen to make use of a couple of .js include files to handle
      things like price conversion, should you want to take a look.

      Also my automatic order forms display the day and date, which sounds
      like what you are trying to do.

      This is the code that I use...

      var Months=new Array ("January","Feb ruary","March", "April","Ma y",
      "June","July"," August","Septem ber","October", "November","Dec ember");

      var Days=new Array("Sunday", "Monday","Tuesd ay","Wednesday" ,
      "Thursday","Fri day","Saturday" );

      function ShowDate()
      {
      var today = new Date();
      var year=today.getY ear();
      if (year < 500)
      year = year + 1900;
      document.write(
      Days[today.getDay()] + ", " +
      today.getDate() + " " +
      Months[today.getMonth( )] + ", " +
      year+".");
      }

      Cardman


      Comment

      • Trevor Stapleton

        #4
        Re: external .js page

        On Sun, 01 Feb 2004 00:25:33 +0100, Juliette
        <"jrf[spamblock]"@jokeaday. net> wrote:
        [color=blue]
        >http://www.jibbering.com/faq/
        >
        >But just to help you on your way (code presumes you put your js include
        >files in a seperate directory called "include"):[/color]
        [color=blue]
        >Good luck, Juliette[/color]

        Thank you for your speedy reply, I now have my script up and running
        the pain problem was i had left a </SCRIPT> in the .js file and on the
        page.

        Thank you once again to for taking the time and trouble of answering
        my question, i have visited the above web site as suggested.

        Comment

        • Trevor Stapleton

          #5
          Re: external .js page

          On Sun, 01 Feb 2004 02:08:34 +0000, Cardman <do-not@spam-me.com>
          wrote:
          Thanks for the reply, I have found the reason the script would not
          work
          it was a human error, mine, I had left a </SCRIPT> on the .js file
          as well as on the page, one to many ( now were have I heard that
          before?) thanks for the code and the reply

          Comment

          • Cardman

            #6
            Re: external .js page

            On Sun, 01 Feb 2004 13:26:43 +0000, Trevor Stapleton
            <trevor.staplet on@ntlworld.com > wrote:
            [color=blue]
            >Thanks for the reply, I have found the reason the script would not
            >work it was a human error, mine,[/color]

            Well that happens sometimes due to "bug" errors, either due to typing
            too fast, not checking well enough, or your brain stops working for a
            short time. :-]

            Your problem though was due to learning about JavaScript, when
            everyone has to learn sometime.

            Currently have just started on Perl and CGI myself, where I am getting
            nowhere quickly. I think that I will have to ask my hosting provider
            just where they have left Perl on my system, when CGI only works with
            compiled files so far.

            If only I had Telnet access...
            [color=blue]
            >I had left a </SCRIPT> on the .js file
            >as well as on the page,[/color]

            Yes I did that once, when first using include files, but I spotted the
            problem quite quickly.

            The problem I expect occurs by seeing JavaScript outside of <SCRIPT>
            </SCRIPT> statements, which is just not normal.
            [color=blue]
            >one to many ( now were have I heard that
            >before?) thanks for the code and the reply[/color]

            Good luck with the rest of your project then.

            Cardman


            Comment

            • Dr John Stockton

              #7
              external .js page

              JRS: In article <r6do10139t2um9 kshhgo4h4dpch2p nvc8h@4ax.com>, seen in
              news:comp.lang. javascript, Trevor Stapleton <trevor.staplet on@ntlworld.c
              om> posted at Sat, 31 Jan 2004 23:14:39 :-[color=blue]
              >
              >I have a small script (it prints the date in the UK fashion ) that i
              >want to include on several but not all the pages on my web site.
              >it seems illogical to type all the code on every page, I understand I
              >can put the code in a file lets call it do_date.js and have it used by
              >the pages it is needed on, i just don't seem to be able to get it to
              >work, suggestions would be most welcome>[/color]

              <URL:http://www.merlyn.demo n.co.uk/js-nclds.htm>
              <URL:http://www.merlyn.demo n.co.uk/js-dates.htm>
              <URL:http://www.merlyn.demo n.co.uk/js-index.htm>

              But, unless you are forced to do so, don't use DD/MM/YYYY ; use the ISO-
              8601 format YYYY-MM-DD which everyone can understand.

              --
              © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
              <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
              <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
              <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

              Comment

              Working...