Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-10-2012, 01:24 PM   PM User | #1
domitbg
New to the CF scene

 
Join Date: Dec 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
domitbg is an unknown quantity at this point
Question Display Message By day and time

Hello i got a problem i know how to make a display message by day code but i need one that for example te massage of the day will change at 10am not at midnight. I wan't to do be through monday to sunday. Thx
domitbg is offline   Reply With Quote
Old 12-10-2012, 03:18 PM   PM User | #2
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,382
Thanks: 3
Thanked 466 Times in 453 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
  <title></title>

</head>

<body>
<div id="tst" ></div>

<script type="text/javascript">
<!--
var Messages=['Day 0','Day 1','Day 2','Day 3','Day 4','Day 5','Day 6'];

function Message(id,ary,hr){
 var date=new Date(),obj=document.getElementById(id),hr=typeof(hr)=='number'&&hr>=0&&hr<=24?hr:24;
 if (obj&&typeof(ary)=='object'&&ary.constructor==Array&&ary[0]){
  obj.innerHTML=ary[date.getDay()+(date.getHours()>=hr?1:0)]||ary[0];
 }
}
Message('tst',Messages,10);
//-->
</script>
</body>

</html>
__________________
Vic

God Loves You and will never love you less.

http://www.vicsjavascripts.org.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/

Last edited by vwphillips; 12-10-2012 at 03:55 PM..
vwphillips is offline   Reply With Quote
Old 12-10-2012, 03:49 PM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Code:
<div id = "dailymessage"></div>

<script type = "text/javascript">

var messages = [];
messages[0]= "Sunday Message"
messages[1] = "Monday message";
messages[2] = "Tueday message"
messages[3] = "Wednesday message"
messages[4] = "Thursday message"
messages[5] = "Friday message";
messages[6] = "Saturday message";

var d = new Date();   // today
d = d.getTime() - 36000000;  // subtract 10 hours
var nd = new Date(d);
var dy = nd.getDay();
document.getElementById("dailymessage").innerHTML = messages[dy];

</script>

"I have never taken any exercise except sleeping and resting." - Mark Twain, US humorist, novelist, short story author, & wit (1835 - 1910)
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 12-10-2012, 04:22 PM   PM User | #4
domitbg
New to the CF scene

 
Join Date: Dec 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
domitbg is an unknown quantity at this point
How about if i wan't to input an image insted of a text im tyring <img></img> but it's not working
domitbg is offline   Reply With Quote
Old 12-10-2012, 04:32 PM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Code:
var please = false;
var thanks = false;
if (!please && !thanks) {
var interestLost = true;
var moreHelp = 0;
}
This is very easy - simply displaying an image - and you ought to be able to do it yourself. You have been given the code to make the daily change at 1000.

Why do you think that the word want has an apostrophe in it?
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 12-10-2012 at 04:49 PM..
Philip M is offline   Reply With Quote
Old 12-10-2012, 04:53 PM   PM User | #6
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,382
Thanks: 3
Thanked 466 Times in 453 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
  <title></title>

</head>

<body>
<img id="tst" src="http://www.vicsjavascripts.org.uk/StdImages/Blank.gif" alt="img">
<script type="text/javascript">
<!--
var Messages=['http://www.vicsjavascripts.org.uk/StdImages/1.gif','http://www.vicsjavascripts.org.uk/StdImages/2.gif','http://www.vicsjavascripts.org.uk/StdImages/3.gif','http://www.vicsjavascripts.org.uk/StdImages/4.gif','http://www.vicsjavascripts.org.uk/StdImages/5.gif','http://www.vicsjavascripts.org.uk/StdImages/6.gif','http://www.vicsjavascripts.org.uk/StdImages/7.gif'];

function Message(id,ary,hr){
 var date=new Date(),obj=document.getElementById(id),hr=typeof(hr)=='number'&&hr>=0&&hr<=24?hr:24;
 if (obj&&typeof(ary)=='object'&&ary.constructor==Array&&ary[0]){
  obj.src=ary[date.getDay()+(date.getHours()>=hr?1:0)]||ary[0];
 }
}
Message('tst',Messages,10);
//-->
</script>
</body>

</html>
__________________
Vic

God Loves You and will never love you less.

http://www.vicsjavascripts.org.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/
vwphillips is offline   Reply With Quote
Old 12-10-2012, 05:02 PM   PM User | #7
domitbg
New to the CF scene

 
Join Date: Dec 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
domitbg is an unknown quantity at this point
Thanks allot guys ye there shouldn't be a ( ' ) at (want) :P

Last edited by domitbg; 12-10-2012 at 05:14 PM..
domitbg is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:26 AM.


Advertisement
Log in to turn off these ads.