Enjoy an ad free experience by logging in. Not a member yet?
Register .
09-21-2011, 04:04 PM
PM User |
#1
New Coder
Join Date: Jan 2004
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
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>:
09-21-2011, 04:33 PM
PM User |
#2
New Coder
Join Date: Apr 2010
Location: Norfolk, England
Posts: 63
Thanks: 1
Thanked 14 Times in 14 Posts
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 ..
Users who have thanked thesam101 for this post:
09-21-2011, 05:32 PM
PM User |
#3
New Coder
Join Date: Jan 2004
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
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
09-21-2011, 05:45 PM
PM User |
#4
Senior Coder
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
post the entire code including html so we can see how you are callign the function
09-21-2011, 05:47 PM
PM User |
#5
Senior Coder
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
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>
Users who have thanked DanInMa for this post:
09-21-2011, 06:14 PM
PM User |
#6
New Coder
Join Date: Jan 2004
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
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>
09-21-2011, 06:15 PM
PM User |
#7
Senior Coder
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
Thanks for "reading" the answers
09-21-2011, 06:22 PM
PM User |
#8
New Coder
Join Date: Apr 2010
Location: Norfolk, England
Posts: 63
Thanks: 1
Thanked 14 Times in 14 Posts
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.//
Users who have thanked thesam101 for this post:
09-21-2011, 06:25 PM
PM User |
#9
Senior Coder
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
I would have left him/her in the lurch ..
09-21-2011, 06:29 PM
PM User |
#10
New Coder
Join Date: Jan 2004
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
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>
09-21-2011, 06:35 PM
PM User |
#11
Senior Coder
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
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);
}
Users who have thanked devnull69 for this post:
09-21-2011, 06:50 PM
PM User |
#12
New Coder
Join Date: Jan 2004
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
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>
Jump To Top of Thread
Thread Tools
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
HTML code is Off
All times are GMT +1. The time now is 09:42 PM .
Advertisement
Log in to turn off these ads.