swapping image with getHours()

Ask a Question related to Macromedia Dynamic HTML, Design and Development.

  1. #1

    Default swapping image with getHours()

    I want to swap images in a div using javascript getHours(). I've done it in
    Flash and it worked fine, yet it doesn't seem to here.
    Here's the code I have:



    <div id="logo" style="margin:5px 0 0
    5px;height:200px;width:200px;cursor:pointer">
    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
    <!--
    var dt:Date=new Date();
    var hour=dt.getHours();
    if (hour>=6 && hour<=14){
    document.write("<img src=logo1.jpg'>")
    } else
    if (hour>=14 && hour<=16){
    document.write("<img src='logo2.jpg'>")
    } else
    if (hour>=16 && hour<=20){
    document.write("<img src='logo3.jpg'>")
    } else
    if ((hour>=20 && hour<=23) || (hour>=0 && hour<=6)){
    document.write("<img src='logo4.jpg'>")
    } else {
    document.write("<img src='logo1.jpg'>")
    }
    // -->
    </SCRIPT>
    </div>

    skot:317 Guest

  2. Similar Questions and Discussions

    1. image swapping urgent
      hi all need help with image swapping. its perfectly working in my system offline as well as online. but its not showing the image in other...
    2. need help with image swapping.
      hi all need help with image swapping. its perfectly working in my system offline as well as online. but its not showing the image in other...
    3. text and image swapping
      Hi Guys, returning to Director after a long while. My memory has faded on me so I hope that you will give me a hand! I need to create a...
    4. image swapping in php
      "Richard" <anom@anom> schrieb im Newsbeitrag news:bm50kc0sgn@enews2.newsguy.com... You can't do that. A mouseover event is processed at the...
    5. Image Swapping (Not Rollover)
      I have an online portfolio to display my photography work, and on one page i have a list on the left, and i have the photographs on the right, i want...
  3. #2

    Default Re: swapping image with getHours()


    You have an invalid var declaration. You can't use the semicolon in a var :
    var dt:Date=new Date();
    should be ... var dt=new Date();

    There's also an error in your first image.. It's missing the first ' in the
    img src.
    document.write("<img src=logo1.jpg'>")
    should be ... document.write("<img src='logo1.jpg'>")


    --
    Regards,
    ...Trent Pastrana
    [url]www.fourlevel.com[/url]

    Dreamweaver Designer Tools
    iFrameSuite | MiniMenus | Scroller Packages | More...
    -----------------------------



    "skot:317" <webforumsuser@macromedia.com> wrote in message
    news:dap54t$eae$1@forums.macromedia.com...
    >I want to swap images in a div using javascript getHours(). I've done it in
    > Flash and it worked fine, yet it doesn't seem to here.
    > Here's the code I have:
    >
    >
    >
    > <div id="logo" style="margin:5px 0 0
    > 5px;height:200px;width:200px;cursor:pointer">
    > <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
    > <!--
    > var dt:Date=new Date();
    > var hour=dt.getHours();
    > if (hour>=6 && hour<=14){
    > document.write("<img src=logo1.jpg'>")
    > } else
    > if (hour>=14 && hour<=16){
    > document.write("<img src='logo2.jpg'>")
    > } else
    > if (hour>=16 && hour<=20){
    > document.write("<img src='logo3.jpg'>")
    > } else
    > if ((hour>=20 && hour<=23) || (hour>=0 && hour<=6)){
    > document.write("<img src='logo4.jpg'>")
    > } else {
    > document.write("<img src='logo1.jpg'>")
    > }
    > // -->
    > </SCRIPT>
    > </div>
    >

    T.Pastrana - 4Level Guest

  4. #3

    Default Re: swapping image with getHours()

    You are right, it was the :Date that was not correct.

    Thanks!
    skot:317 Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139