SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast ttcf's Avatar
    Join Date
    Nov 2001
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Please have a butches at this

    Please can you look at this script. I am trying to make it so a different image is on the site at different times of the year. But this just is not working.


    <BODY BGCOLOR = maroon TEXT=cornsilk>

    <SCRIPT LANGUAGE = Javascript>
    <!--
    currentDate = new Date();
    var currentDay = currentDate.getDate();
    var currentMonth = currentDate.getMonth() + 1;


    //set the default text and image
    welcomeText = Welcome to my site
    imageFile = welcome.gif


    //test for holidays and set text and images to suit first match
    if ((currentDay >= 12) && (currentMonth == 12)) {
    welcomeText = Seasons<BR>Greetings;
    imageFile = season.gif;


    } else if ((currentMonth >= 11) || (currentMonth <= 2)) {
    welcomeText = Wishing you<BR>Winter Warmth ;
    imageFile = winter.gif;


    } else if ((currentMonth >= 6) && (currentMonth <= 8)) {
    welcomeText = It’ Summer<BR>Holiday time ;
    imageFile = summer.gif;}


    //compose the HTML for the page into a variable called pageText
    pageText = ‘<center><img src=’ + imageFile + ‘>’
    pageText += ‘<P><H1>’ + welcomeText
    //write the HTML to the screen
    document.writeln(pageText)
    //-->
    </SCRIPT>

    <NOSCRIPT>Your browser doesn’t support scripts</NOSCRIPT>

  2. #2
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    currentDate = new Date(); 
    var currentDay = currentDate.getDate(); 
    var currentMonth = currentDate.getMonth() + 1;
    Try initializing the variable imageFile
    var imageFile="welcome.gif";
    var welcomeText="Welcome to my site";

    Also always put quotations around everything saves on potential errors.

    Code:
    //compose the HTML for the page into a variable called pageText 
    pageText = ‘<center><img src=’ + imageFile + ‘>’ 
    pageText += ‘<P><H1>’ + welcomeText 
    //write the HTML to the screen 
    document.writeln(pageText) 
    //-->
    Change to this
    Code:
    var pageText="";
    pageText = "<center><img src='"+imageFile+"'>"
    pageText += "<p><h1>" + welcomeText
    Try and use double quotes as sometimes browsers are really picky.

    I don't see anything 'wrong' with your code. I see some things that may cause errors. So fix those and see if they help.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.


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
  •