SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Expected ';' but can't find the problem

    Hello,

    I am trying to find an error which keeps appearing on a web page. the scripts function correctly but I would like to remove the warning in the status bar.

    error reported is: Expected ','

    Code JavaScript:
      <script type="text/javascript" language="JavaScript">
      <!--
        var now = new Date();
        var days = new Array[
          'Sunday','Monday','Tuesday',
          'Wednesday','Thursday','Friday','Saturday'];
        var months = new Array[
          'January','February','March','April','May',
          'June','July','August','September','October',
          'November','December'];
        var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
        function fourdigits(number) {
          return (number < 1000) ? number + 1900 : number;}
        today =  days[now.getDay()] + ", " +
          date + " " +
            months[now.getMonth()] + " " +
           (fourdigits(now.getYear()));
         document.write(today);
      //-->
    </script> <a href="http://dww/?sethome=mypage.html" class="about_service" onclick="javascript:window.location.href=http://mysite;">Make this my homepage</a>

    The line referred to is the last line posted above. Can anyone help me out?

  2. #2
    SitePoint Wizard bronze trophy Tyssen's Avatar
    Join Date
    Oct 2005
    Location
    Brisbane, QLD
    Posts
    4,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's this line isn't it?

    return (number < 1000) ? number + 1900 : number;}

    You've got a closing } but you haven't got an opening one.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    changing that line didn't seem to help. I believe the problem is within the homepage link or a conflict between the two codes, since if you remove the 'make this my hompage' line, no errors are received.

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your days and months arrays are not correct.

    When defining Arrays using the constructor, you need to use round brackets instead of square ones.

    ie

    Code:
        var days = new Array(
          'Sunday','Monday','Tuesday',
          'Wednesday','Thursday','Friday','Saturday');
        var months = new Array(
          'January','February','March','April','May',
          'June','July','August','September','October',
          'November','December');


  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks but I only changed them after a comment from another person. Either way, it makes no difference to the functionality or the error.

    Could there be another reason the page is returning a javascript error?

  6. #6
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Location
    San Francisco, CA
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In your last line, put single quote around the location:

    javascript:window.location.href='http://mysite';

    You probably don't even need the ";" at the end there.
    Comments, Review, Forum Widgets: http://www.nuharbor.com

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That was it, thank you very much.

    I really need to learn javascript one of these days


Bookmarks

Posting Permissions

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