Difficult Javascript Problem!

This is a discussion on "Difficult Javascript Problem!" within the JavaScript Forum section. This forum, and the thread "Difficult Javascript Problem! are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Dec 6th, 2005, 18:50
craig's Avatar
Reputable Member
Join Date: Sep 2005
Location: Preston, UK
Age: 21
Posts: 381
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to craig
Exclamation Difficult Javascript Problem!

Hi guys,
Here's one to rack your brains over.
I want to use a javascript in order to change the color of some text depending on the current date. For example, i want to define 2 dates, and if the current date is within those 2 dates it displays one colored text and if it is outside that date it displays a different colored text.
To get an example of what i mean go to www.ecampsite.co.uk/somerset.php
If a campsite is open, the text will be green, and if it is closed it is orange. Is there any way to automate this with javascript??
Your input regarding this will be invaluable!
Thank you
Craig
Reply With Quote

  #2 (permalink)  
Old Dec 6th, 2005, 20:35
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
Re: Difficult Javascript Problem!

cant you do that with php?
Reply With Quote
  #3 (permalink)  
Old Dec 6th, 2005, 20:53
craig's Avatar
Reputable Member
Join Date: Sep 2005
Location: Preston, UK
Age: 21
Posts: 381
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to craig
Exclamation Re: Difficult Javascript Problem!

i dont have have a database, would you be able to do it thru just php on a page, that would be a mega help!!!
Reply With Quote
  #4 (permalink)  
Old Dec 6th, 2005, 21:05
Highly Reputable Member
Join Date: May 2005
Location: U.K
Age: 21
Posts: 739
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbramz
Re: Difficult Javascript Problem!

yeah you can use if statments, for example:

php:
PHP: Select all

<? if $variable == "new" {
 echo 
"new text output or whatever" ;
} elseif 
$variable == "full"
echo "red text or whatever" ;
} else {
echo
"green text" ;
}
?>
or even asp
Code: Select all
<% if variable = "full" then 
response.write "full dude"
elseif variable = "new" then
response.write"new or whatever"
else
response.write "woohoo we have places"
end if %>
make sense?
Reply With Quote
  #5 (permalink)  
Old Dec 6th, 2005, 21:25
craig's Avatar
Reputable Member
Join Date: Sep 2005
Location: Preston, UK
Age: 21
Posts: 381
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to craig
Re: Difficult Javascript Problem!

how would i write an if statement, if the criteria was between 2 dates? and if the it is between the dates, it would change the text color to a different color.
Its not really whether we're full, but i think it would be somewhere along those lines!! Thank you so far!!!
Reply With Quote
  #6 (permalink)  
Old Dec 6th, 2005, 21:48
Highly Reputable Member
Join Date: May 2005
Location: U.K
Age: 21
Posts: 739
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbramz
Re: Difficult Javascript Problem!

you see this would be easier if you had a database...

as each date will have to be a variable so you have to edit each page...so basicly just adding the colour yourself would be better...

if you had a database you could just have an admin backend and make the script do all the work...
Reply With Quote
  #7 (permalink)  
Old Dec 7th, 2005, 02:10
craig's Avatar
Reputable Member
Join Date: Sep 2005
Location: Preston, UK
Age: 21
Posts: 381
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to craig
Re: Difficult Javascript Problem!

SOLVED - a good friend of mine (a bloody genius) has written some php code for me which solves my problem!!!
Craig

Code: Select all
function OCText($opendate,$closedate)
{
  if ( strtotime("now") > $opendate && strtotime("now") < $closedate )
  {
    return "Open";
  }
  else 
  {
    return "Closed";
  }
}
Reply With Quote
  #8 (permalink)  
Old Dec 7th, 2005, 09:36
Highly Reputable Member
Join Date: May 2005
Location: U.K
Age: 21
Posts: 739
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbramz
Re: Difficult Javascript Problem!

there ya go then
Reply With Quote
Reply

Tags
difficult, javascript, problem

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Would this be difficult to do AdRock Webforumz Suggestions and Feedback 6 Nov 6th, 2007 12:42
Javascript problem zc1 JavaScript Forum 2 Jan 15th, 2007 17:01
Is something like this too difficult to create? andresnav Introduce Yourself 7 Nov 19th, 2006 05:58
too difficult for a noob Cam PHP Forum 5 Feb 4th, 2004 22:15
CSS Difficult? Galaxyblue Web Page Design 11 Jan 27th, 2004 19:18


All times are GMT. The time now is 10:25.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

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