user1108948
user1108948

Reputation:

Display last and next month in a simple calendar

Here is the demo.

I created a simple calendar and it works out for the current month. However I have "<<" and ">> to indicate last and next month, clicking them just not working.

A piece of code:

prevMonth:function(){
    var month = $('.u-start-month').text(),
        year = $('.u-start-year').text();
    if(month <= 1){
        month = 12;
        --year;
    }
    else{
        --month;
    }
    this.initDate(year, month, $.proxy(function(){
        this.dir = 'left';
        this.init(year, month);
    }, this));
},

Did I miss something?

Upvotes: 0

Views: 1574

Answers (2)

Gyandeep
Gyandeep

Reputation: 13538

Add the onclick event directly in your HTML code: http://jsbin.com/piqatota/1/edit?html,js,output

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script><div class="u-start">
    <div class="u-start-header">
        <div class="u-start-prev" onclick="Start.prevMonth();"><<</div>
        <div class="u-start-date">
            <strong>Start Calander</strong>
            <span><em class="u-start-year"></em>-<em class="u-start-month"></em></span>
        </div>
        <div class="u-start-next" onclick="Start.nextMonth();">>></div>
    </div>
    <table class="u-start-body"></table>
    <div class="u-start-footer"></div>
</div>

Upvotes: 1

Bryce Easley
Bryce Easley

Reputation: 4841

Nothing was missing it just seems you never hooked up an event handler for the function. So just add this

jQuery

 $('.u-start-prev').on('click',function(){

        Start.prevMonth();

    });
     $('.u-start-next').on('click',function(){

        Start.nextMonth();

    });

And it seems to be working after that. Here is the fiddle with it working. Let me know if I misunderstood something.

http://jsfiddle.net/44LpP/2/

Upvotes: 2

Related Questions