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

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 09-21-2011, 04:04 PM   PM User | #1
rsines
New Coder

 
Join Date: Jan 2004
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
rsines is an unknown quantity at this point
Question I Need "Help" with Syntax Error

I've been searching the web trying to find a way to redirect based on a date range, I've not found the exact code, but as much as I can make out this should be pretty close. Could someone tell me why I keep getting an error?

<script type="text/javascript">
function newLocation()
{
var today = new Date();
var daynum = today.getDOY();

if (daynum => 243 && daynum <= 283) {window.location("my.html")}
else {window.location("your.html")}
}
</script>:
rsines is offline   Reply With Quote
Old 09-21-2011, 04:33 PM   PM User | #2
thesam101
New Coder

 
Join Date: Apr 2010
Location: Norfolk, England
Posts: 63
Thanks: 1
Thanked 14 Times in 14 Posts
thesam101 is an unknown quantity at this point
Hi rsines

Code:
<script type="text/javascript">
function newLocation()
{
   var today = new Date();
   var daynum = today.getDOY();

   if ((daynum => 243)&&(daynum <= 283))
   {
     window.location.href = "my.html";
   }
   else 
   {
      window.location.href = "your.html";
   }
}
</script>
__________________
//Improvement in coding is iterative, each 'failure' is just the next step on your learning curve, some knowledge and logic can get you a long way.//

Last edited by thesam101; 09-21-2011 at 04:38 PM..
thesam101 is offline   Reply With Quote
Users who have thanked thesam101 for this post:
rsines (09-21-2011)
Old 09-21-2011, 05:32 PM   PM User | #3
rsines
New Coder

 
Join Date: Jan 2004
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
rsines is an unknown quantity at this point
I still get the syntax error. I admit I didn't try seperating the conditions that way though. I've added semicolons brackets, everything I've seen done on the web but I still get the error. Thanks for the help
rsines is offline   Reply With Quote
Old 09-21-2011, 05:45 PM   PM User | #4
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
post the entire code including html so we can see how you are callign the function
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 09-21-2011, 05:47 PM   PM User | #5
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
also try this: ( http://www.w3schools.com/js/js_comparisons.asp )

Code:
function newLocation()
{
var today = new Date();
var daynum = today.getDOY(); 

if (daynum >= 243 && daynum <= 283) {
	window.location("my.html")
	}
else {
	window.location("your.html")
	}
}
</script>
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Users who have thanked DanInMa for this post:
rsines (09-21-2011)
Old 09-21-2011, 06:14 PM   PM User | #6
rsines
New Coder

 
Join Date: Jan 2004
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
rsines is an unknown quantity at this point
New Error

Thanks again for the "HELP":

A Runtime Error has occured
Error: Object doesn't support this property or method

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Page Redirect</title>

<script type="text/javascript">
function newLocation()
{
var today = new Date();
var daynum = today.getDOY();

if (daynum >= 243 && daynum <= 283) {
window.location("my.html")
}
else {
window.location("your.html")
}
}
</script>

</head>
<body>

<center>
<form>
<input type="button" value="Click me!" onclick="newLocation()" />
</form>
</center>

</body>
</html>
rsines is offline   Reply With Quote
Old 09-21-2011, 06:15 PM   PM User | #7
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Thanks for "reading" the answers
devnull69 is offline   Reply With Quote
Old 09-21-2011, 06:22 PM   PM User | #8
thesam101
New Coder

 
Join Date: Apr 2010
Location: Norfolk, England
Posts: 63
Thanks: 1
Thanked 14 Times in 14 Posts
thesam101 is an unknown quantity at this point
You didnt use my code

the main fix in my code was this:

Code:
window.location("your.html")
should be this:

Code:
window.location.href = "your.html";

The code I provided, was yours but fixed.
__________________
//Improvement in coding is iterative, each 'failure' is just the next step on your learning curve, some knowledge and logic can get you a long way.//
thesam101 is offline   Reply With Quote
Users who have thanked thesam101 for this post:
rsines (09-21-2011)
Old 09-21-2011, 06:25 PM   PM User | #9
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
I would have left him/her in the lurch ..
devnull69 is offline   Reply With Quote
Old 09-21-2011, 06:29 PM   PM User | #10
rsines
New Coder

 
Join Date: Jan 2004
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
rsines is an unknown quantity at this point
Thanks again for the "HELP":

Same Error Message

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Page Redirect</title>

<script type="text/javascript">
function newLocation()
{
var today = new Date();
var daynum = today.getDOY();

if (daynum >= 243 && daynum <= 283) {
window.location = "my.html";
}
else {
window.location = "your.html";
}
}
</script>

</head>
<body>

<center>
<form>
<input type="button" value="Click me!" onclick="newLocation()" />
</form>
</center>

</body>
</html>
rsines is offline   Reply With Quote
Old 09-21-2011, 06:35 PM   PM User | #11
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
It's still window.location.href ... but where is your getDOY() defined? It's not a javascript standard. Try to add this
Code:
Date.prototype.getDOY = function() {
   var onejan = new Date(this.getFullYear(),0,1);
   return Math.ceil((this - onejan) / 86400000);
}
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
rsines (09-21-2011)
Old 09-21-2011, 06:50 PM   PM User | #12
rsines
New Coder

 
Join Date: Jan 2004
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
rsines is an unknown quantity at this point
Thumbs up Resolved

THANK YOU! THANK YOU! THANK YOU!

It now works:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Page Redirect</title>

<script type="text/javascript">

Date.prototype.getDOY = function() {
var onejan = new Date(this.getFullYear(),0,1);
return Math.ceil((this - onejan) / 86400000);
}

function newLocation()
{
var today = new Date();

var daynum = today.getDOY();

if (daynum >= 243 && daynum <= 283) {
window.location = "my.html";
}
else {
window.location = "your.html";
}
}
</script>

</head>
<body>

<center>
<form>
<input type="button" value="Click me!" onclick="newLocation()" />
</form>
</center>

</body>
</html>
rsines 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 09:42 PM.


Advertisement
Log in to turn off these ads.