/    Sign up×
Community /Pin to ProfileBookmark

How to make javascript use exact time

I m trying to change table cell colour on exact time. I added cell id and i can change that cell bacground colour on time between 5-6 or on every other time. But i want to change color on 5 and 15 for example. On if variable i added minutes after hours but then javascript dont understand that they are together. In this situation color chanes exactly on 5 and on every hour who have less then 15 minutes.

[code]
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var psj=0;

//ujutro od 5-6
if (hours = 5 && minutes < 15){
var i=document.getElementById(“2”);
var colori=[‘#008000′,’#ff0000’];
var nextColori=0;

setInterval(“i.style.backgroundColor=colori[nextColori++%colori.length];”+
“f.style.backgroundColor=colori1[nextColori1++%colori1.length];”,500);
}
[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@thraddashDec 06.2009 — There seems to be lines of code missing or left out of your example (like the f variable).

Remember that = is an assignment operator, and == is a comparison operator (In the IF statement).

Also you should not give an element an id that starts with a number.

[CODE]var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var psj = 0;

//ujutro od 5-6
if (hours [COLOR="Blue"]==[/COLOR] 5 && minutes < 15) {
var i = document.getElementById([COLOR="Red"]"2"[/COLOR]);
var colori = ['#008000','#ff0000'];
var nextColori = 0;

setInterval(
"i.style.backgroundColor=colori[nextColori++&#37;colori.length];" +
"f.style.backgroundColor=colori1[nextColori1++%colori1.length];"
,500
);
}[/CODE]
Copy linkTweet thisAlerts:
@majstaauthorDec 06.2009 — hehe yeah that was the problem thanks a lot ?
Copy linkTweet thisAlerts:
@KorDec 07.2009 — <i>
</i>var i=document.getElementById("[COLOR="Red"]2[/COLOR]");

Maybe not a fundamental error (and it might pass unseen), but you should know that[B] id[/B] and [B]name[/B] should not start with a digit:

"ID and NAME tokens [COLOR="Blue"]must begin with a letter[/COLOR] ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".")." - [I]W3C Recommendation, Basic HTML Data Types[/I]
×

Success!

Help @majsta spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...