Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Jan 2004
    Posts
    12
    Thanks
    5
    Thanked 0 Times in 0 Posts

    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>:

  • #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>
    Last edited by thesam101; 09-21-2011 at 04:38 PM.
    //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:

    rsines (09-21-2011)

  • #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

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    post the entire code including html so we can see how you are callign the function

  • #5
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 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:

    rsines (09-21-2011)

  • #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>

  • #7
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    Thanks for "reading" the answers

  • #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:

    rsines (09-21-2011)

  • #9
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    I would have left him/her in the lurch ..

  • #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>

  • #11
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 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:

    rsines (09-21-2011)

  • #12
    New Coder
    Join Date
    Jan 2004
    Posts
    12
    Thanks
    5
    Thanked 0 Times in 0 Posts

    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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •