/    Sign up×
Community /Pin to ProfileBookmark

Java Script Image Help

Hi I was wondering if someone could help me with a script
what i want to do is change an image at a certain time which is in hours and minutes. heres what i have done but it doesnt seem to work

<SCRIPT LANGUAGE = ‘JavaScript’><!–
var time = new Date();
var hours = time.getHours();
var minutes = time.getMinutes();
if (hours > 19 && minutes > 5 && hours < 23 && minutes < 20)
document.write(“<IMG SRC=’http://www.westairairlines.com/Cat%20Routes/images/Boarding Lights red.gif’>”)
else
document.write(“<IMG SRC=’http://www.westairairlines.com/Cat%20Routes/images/Redoff.jpg‘>”);
//–></SCRIPT>

I am trying to build a webpage for a virtual airline. and the script i need is to turn boarding lights on 30 minutes before departure time and turn them off at departure time. Departure time is in both hour and minutes

any help would be much appreciated

Shane

to post a comment
JavaScript

23 Comments(s)

Copy linkTweet thisAlerts:
@96turnerriMar 30.2005 — i think getHours and getMinutes return values as a string so putting 19, 5, 23, and 20 in quotes should help fix it
Copy linkTweet thisAlerts:
@js_prof_consMar 30.2005 — I'm not sure about 96's post; however, an error in your code has been made. Your two man conditions need to be in ()s:([b]([/b]hours &gt; 19 &amp;&amp; minutes &gt; 5[b])[/b] &amp;&amp; [b]([/b]hours &lt; 23 &amp;&amp; minutes &lt; 20[b])[/b])Did you get an error when you ran it, or did it just not work?
Copy linkTweet thisAlerts:
@96turnerriMar 30.2005 — dont you mean

((hours > 19 && minutes > 5) && (hours < 23 && minutes < 20))
Copy linkTweet thisAlerts:
@js_prof_consMar 30.2005 — dont you mean

((hours > 19 && minutes > 5) && (hours < 23 && minutes < 20))[/QUOTE]
Yes, thanks for pointing that out. I have changed it just so the original poster doesn't copy bad code. Good eyes. :eek:
Copy linkTweet thisAlerts:
@Rusty073authorMar 30.2005 — Thanks Guys you have been a real Help I have been stuck on tis bit of code for about a week and couldn't pin piont it if yu look at this url you cna see what i wanted it for [URL=Http://www.westairairlines.com/Cat%20Routes/CAT1routes.htm]this is the url[/URL]

Shane
Copy linkTweet thisAlerts:
@js_prof_consMar 30.2005 — Yup, glad to know everything is working!
Copy linkTweet thisAlerts:
@Rusty073authorMar 31.2005 — Hi guys thanks for your help but it does not seem to be working correct me if i read the code wrong what i want the code to do is if hours is greater than 19 and minutes is greater than 5 and less than 23 hours 20 minutes turn on eldse turn off
Copy linkTweet thisAlerts:
@Orc_ScorcherMar 31.2005 — That's confusing. Do you want the off image between 19:05-23:20, between 20:05-22:20 or what?
Copy linkTweet thisAlerts:
@KorMar 31.2005 — try

var lim = hours*60;

if(lim>(19*
50+5) && lim<(23*60+20))
Copy linkTweet thisAlerts:
@Rusty073authorMar 31.2005 — Ok here is what i want at 19.05 i want the lights to turn on then at 23.20 i want them to switch off I hope this makes sence

Rusty073
Copy linkTweet thisAlerts:
@Rusty073authorMar 31.2005 — I use a gif animation to make the lights flash and a standard image for its off state. So all i want to do is between two times flas else turn off (off Image)

Rusty073
Copy linkTweet thisAlerts:
@KorMar 31.2005 — try

var lim = hours*60[COLOR=Red]+minutes[/COLOR];

if(lim>(19*
50+5) && lim<(23*60+20))
Copy linkTweet thisAlerts:
@Rusty073authorMar 31.2005 — Thanks Kor i will give that a try

this is my first attempt at making a scrip and have been trying for a week before actually asking someone.

Rusty073
Copy linkTweet thisAlerts:
@KorMar 31.2005 — Sorry. I have to modify a little bit, i guess my code was not complete


var lim = (hours*60)[COLOR=Red]+minutes[/COLOR;

if(lim>(19
*
60+5) && lim<(23*60+20))



the ideea is simple... You need the same common units.Transform the hours in minutes soo that now you can add/substract those 5 and 20 minutes...



You may as well to transform minutes in hours, but thus would have been more intricate



It is not a matter of javascript. It is a simple math problem. ?
Copy linkTweet thisAlerts:
@Rusty073authorMar 31.2005 — Yes the code does make sence but i cannot test it to my server comes back up online i will let you know how i go

Thanks

Rusty
Copy linkTweet thisAlerts:
@KorMar 31.2005 — you may test such type of codes locally, on your PC. Just change it's time settings
Copy linkTweet thisAlerts:
@KorMar 31.2005 — On the other hand I must warn you that the code, as it is, will return the [b]user's[/b] computer time, not your server's time... If the user is on another time zone, the code will start upon his time....
Copy linkTweet thisAlerts:
@Rusty073authorMar 31.2005 — Yes Kor i am aware of that but that is what i wanted the code to do cheers for pointing that out

do i still need the

var hours = time.getHours();

var minutes = time.getMinutes();
Copy linkTweet thisAlerts:
@KorMar 31.2005 — 
do i still need the

var hours = time.getHours();

var minutes = time.getMinutes();[/QUOTE]


do you mean for your present code? Sure. If you need to return a certain time, you may use getTimezoneOffset() method and adding, if needed, the extra summer hour
Copy linkTweet thisAlerts:
@Rusty073authorMar 31.2005 — Thanks Kor All works fine now maybe i should of just asked before attempting javscript for first time lol

Rustyo73
Copy linkTweet thisAlerts:
@Rusty073authorMar 31.2005 — Ok another question now this works for if this time is or that time is now what if i want it to have more than two things for example at 9 - 10 display this, at 10 - 11 display this, at 11 - 12 display this else nothing get displayed

thanks in advance

Rusty
Copy linkTweet thisAlerts:
@KorApr 01.2005 — if(){

...

}

else if(){

...

}

else if(){

...

}
Copy linkTweet thisAlerts:
@Rusty073authorApr 01.2005 — Thanks again Kor it worked a treat i didnt put {} in the equations

Rusty073
×

Success!

Help @Rusty073 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.18,
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,
)...