SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let's say I have 366 text files, one for each day of the year, the filenames being month-day.txt (eg: for today it would be 4-18.txt).

    How do I get to include the day's text file with javascript ?
    (like if I code it today, tomorrow it'd include 4-19.txt automatically)
    [blogger: zengun] [blogware contributor: wordpress]

  2. #2
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A JavaScript include must link to a .js file. The include won't work with a .txt file. How much data is in each of your "daily text files?" If it's not much, you could consider making an array of the data, and using JavaScript to display the proper one depending on what day it is.

    Another option is to include a .js file that has all your daily info in it, and do document.writes, depending on what day it is.

    Either method above gets pretty involved. If you've got the ability, you'd be better off storing and pulling the info from a database.

  3. #3
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I thought about a .js file, and document.write, but the daily stuff is a whole page with dates and happenings, so that's very cumbersome to store in an array, not to mention the size of the resulting file.
    I wish Icould do it with a database but unfortunately we're hosted on the worst server ever: MacOS WebSTAR (I can hear some people laughing now).

    Is this thing possible:

    daydate = new Date();
    document.write("<script src='" + daydate.getMonth() + "-" + daydate.getday() + ".js' language='javascript' type='text/javascript'>")

    ?
    [blogger: zengun] [blogware contributor: wordpress]

  4. #4
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could just do an array of the names of the text files, then do a document.write and write the contents of the file to the page.

    file = new Array();
    file[0] = 'textfiles/4-18.txt;
    file[1] = 'textfiles/4-19.txt';
    file[2] = 'textfiles/4-20.txt';
    file[3] = 'textfiles/4-21.txt';

    then something like this:

    document.write("<!--# include virtual='todays file name goes here' "-->");

    Your page would have to have a .shtml extension, but that might work.

    I'll ask the obvious question. Why don't you just use a database?
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  5. #5
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I could use a database or SSI I wouldn't be here asking for a javascript solution...
    Think that the host for this site is a server that doesn't handle any server-side language except maybe Applescript and MacPerl, but both of these I don't know.
    Last edited by Michel V; Apr 19, 2001 at 08:30.
    [blogger: zengun] [blogware contributor: wordpress]

  6. #6
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok...I figured it was something like that. Just wanted to cover all of the bases.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  7. #7
    SitePoint Addict isuru's Avatar
    Join Date
    Nov 2000
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Shin Ma

    Is this thing possible:

    daydate = new Date();
    document.write("<script src='" + daydate.getMonth() + "-" + daydate.getday() + ".js' language='javascript' type='text/javascript'>")

    ?
    Shin Ma,

    I think this is definitely the best and easiest way to do it. When I was reading your problem, I immediately thought of doing it this way.

    Basically, you would need to name your text files according to the date. So for the text file for the 20/05/2001 you would need to have 20_05_2001.txt (or something similar).

    Then you can include it using (similar to what you have above):
    daydate = new Date();
    document.write("<script src='" + daydate.getday() + "_" + daydate.getmonth() + "_" + daydate.getYear() + ".js"' language='javascript' type='text/javascript'>")

    You would be able to easily test whether this works the way you want by running it and then changing the date on your machine and running it again and so on.
    And there would be no need to mess around with arrays and stuff

    Good Luck


Bookmarks

Posting Permissions

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