Announcement

Collapse
No announcement yet.

Java help please

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Java help please

    Hi

    I am a complete novice with java, however with the help of this forum and the AUG I have managed to write some java to tell the customer when their order will be delivered. I am however having some trouble with getting the last 2 lines to appear green. When I use span style the var no longer appears.

    I'm sure it's simple, please help.

    <script language=JavaScript>
    now = new Date()
    var weekday=new Array(7)
    weekday[0]="Sunday"
    weekday[1]="Monday"
    weekday[2]="Tuesday"
    weekday[3]="Wednesday"
    weekday[4]="Thursday"
    weekday[5]="Friday"
    weekday[6]="Saturday"
    if ( now.getDay() == 6 ) document.write('<span style="color:green;">order now for delivery Tuesday</span>');
    else if ( now.getDay() == 0) document.write('<span style="color:green;">order now for delivery Tuesday</span>');
    else if ( now.getHours() >=13 && now.getDay() == 5 ) document.write('<span style="color:green;">order now for delivery Tuesday</span>');
    else if ( now.getHours() >=13 && now.getDay() == 4 ) document.write('<span style="color:green;">order now for delivery Monday</span>');
    else if ( now.getHours() <13 && now.getDay() == 5 ) document.write('<span style="color:green;">order now for delivery Monday</span>');
    else if ( now.getHours() >=13) document.write("Order now for delivery " + weekday[now.getDay()+2]);
    else if ( now.getHours() <13) document.write("Order now for delivery " + weekday[now.getDay()+1]);
    </script>

    Thanks

    Steven

    #2
    Use single quotes on those last two lines. E.g. document.write('Order now for delivery '

    PS. If all these lines are to be in green, the put the <span style="color:green;"> and the </span> outside the <script ..> and </script>
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      PS. The following may be neater and easier to maintain
      Code:
      <span style="color:green">Order now for delivery 
      <script type="text/javascript">
      var latesthour = 13;
      var weekday = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
      var now = new Date();
      var thisday = weekday[now.getDay()];
      var thishour = now.getHours();
      var delday;
      if ( thisday == 'Sunday' ) delday = 'Tuesday'
       else if ( thisday == 'Saturday' ) delday = 'Tuesday'
        else if ( thisday == 'Friday' && thishour >= latesthour ) delday = 'Tuesday'
         else if ( thisday == 'Friday' && thishour < latesthour ) delday = 'Monday'
          else if ( thisday == 'Thursday' && thishour >= latesthour ) delday = 'Monday'
           else if ( thishour >= latesthour ) delday = weekday[now.getDay() + 2]
            else delday = weekday[now.getDay() + 1];
      document.write(delday);
      </script>
      </span>
      NB not checked for typos.
      Norman - www.drillpine.biz
      Edinburgh, U K / Bitez, Turkey

      Comment


        #4
        Code:
        <span style="color:green">Order now for delivery 
        <script type="text/javascript">
        var weekday = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
        var now = new Date();
        var thisday = weekday[now.getDay()];
        var thishour = now.getHours();
        var delday;
        if ( thisday == 'Saturday' ) delday = 'Tuesday'
         else if ( thisday == 'Sunday' ) delday = 'Tuesday'
          else if ( thisday == 'Friday' && thishour >= 13 ) delday = 'Tuesday'
        
        
        
        document.write(delday)
        </script>
        </span>
        I know you didn't check for erros but document.write(delday> is really gonna confuse a newbie LOL
        Wayne Theisinger

        The Web's just settling in. We got the tech, now let's put up something that matters.

        Comment


          #5
          Ooops. Fixed it in case any one else looks at this later.
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #6
            Thanks for all your help.

            Steven

            Comment

            Working...
            X