www.webdeveloper.com
Results 1 to 6 of 6

Thread: Strange Behavior

  1. #1
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,498

    Strange Behavior

    I have got some strange behavior from a script.

    I am making myself a personal diary script that is a calendar and so far all is going well except for the months aspect of the script. The interface will eventually be linked to a database, that however is a long way off until I get the front end behaving itself, I can't progress.

    First off I have to describe the problem...

    I have four buttons, 1 set (two of the four) for advancing and regressing the years, works perfectly fine, not a problem with that.

    The second set of buttons is for the months. The calendar is designed to start from the current month, so the page loads, in this instance the month being October shows up and when I click the advance month button, it moves to November, December then instead of rolling over in to January and advancing the year, it goes back to October but in the next year...

    Going in the opposite direction, similar happens, instead of December and the year regressing when January is reached, it goes back to October but the year will be October of the previous year.

    I figure its a case of can't see the wood for the trees, so here is the actual logic part of the of the script.

    Code:
    function buttonClick(o){
    	
        switch(o.value){
            // year down
            case "previous year": y--;	break;
            // year up	
            case "next year": y++;	break;
            // month down	
            case "previous month": m = (m>=0)? m-1:11; y = (m==0)? y-1 : y;	break;
            // month up 
            case "next month": m = (m<=11)? m+1:0; y = (m==0)? y+1 : y;	break;
    	
        }
    
    }
    The year buttons and month buttons are attached to the script button click and as soon as a change is made, the display up dates.

    Now...
    Code:
    // year down
        case "previous year": y--;	break;
        // year up	
        case "next year": y++;	break;
    works just fine and dandy... the problem is in this this part
    Code:
    // month down	
        case "previous month": m = (m>=0)? m-1:11; y = (m==0)? y-1 : y;	break;
        // month up 
        case "next month": m = (m<=11)? m+1:0; y = (m==0)? y+1 : y;	break;
    Any ideas...
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  2. #2
    Join Date
    Mar 2009
    Posts
    521
    Shouldn't
    Code:
    case "previous month": m = (m>=0)? m-1:11; y = (m==0)? y-1 : y;	break;
    be

    Code:
    case "previous month": m = (m>=0)? m-1:11; y = (m==11)? y-1 : y;	break;
    and
    Code:
      case "next month": m = (m<=11)? m+1:0; y = (m==0)? y+1 : y;	break;
    be

    Code:
      case "next month": m = (m<=10)? m+1:0; y = (m==0)? y+1 : y;	break;

  3. #3
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,498
    I think that I will just live with it by adding a year up and year down button and work on the month thing fixed so it goes from what ever up and down but no roll around.

    Like I said, its a personal project not for public release, basically a diary for me to put my appointments in to.

    Thanks for trying but no cigar as the saying goes.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  4. #4
    Join Date
    Mar 2009
    Posts
    521
    Sorry for my inferior coding. I promise you I won't bother you in the future with it.

  5. #5
    Join Date
    Sep 2007
    Posts
    317
    If I understand
    Code:
      
    <script type="text/javascript">
    
    
    var d = new Date(); 
    
    //alert(d); 
    var m = d.getMonth()
    
    alert('içinde bulunduğumuz ay= '+m);
    
    var nextMonth = (m + 1) % 12 ;
    
    alert('sonraki ay = '+nextMonth);
    
    var previousMonth = ( m + 11) % 12;
    
    alert('önceki ay = '+previousMonth);
    
    </script>

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,498
    Ayşe, what I was trying to do was to make a forward and back button that would allow me to move back one month at a time or forward and the year to roll over when months regressed , eg, Feb 2013, Jan 2013, Dec 2012 ... and like wise forwards Nov 2013, Dec 2013, Jan 2014

    What was happening was the month for example were in October to be able to advance Oct 2013, Nov 2013, Dec 2013, Jan 2014 and what was actually happening was the calendar was going Oct 2013, Nov 2013, Dec 2013, Oct 2014 and similar when regressing.

    I have since decided to make the script so that I roll the years manually then the months to what I want, as this is for my personal use its not that big a hardship to live with, had this been a public project or for a client then I would have tried solving the issue.

    For those who have tried to help, thanks. Its just a bizarre thing thats happening to the display that I really wanted to check if it was my logic or the script engine as I have already had one incident that turned out to be the script engine but this activity is persistent, therefore the code logic is flawed.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles