How to make this function in JQuery?

Hi there

this is my jsfiddle

What I want that there should be some value change when user clicks on back and next label
Like in current case there is backyear value is 2014 when user clicks on “back” it should change to 2013 and when user clicks on “next” it should change to “2015” in nextyear

How can I acheive this?
I need preconfigured value in js file and there should be a limit on it

This is a rather simple task, so instead of giving complete solution let me help you to make it yourself.

First of all, let’s write an algorithm that will describe what we want to achieve:

  1. Hold two values (prevYear, nextYear) in memory;
  2. Output each of them into corresponding div on the page;
  3. When user clicks “back”:
    3.1. Decrease prevYear value (substract 1 from it);
    3.2. Output new prevYear value into corresponding div;
  4. When user clicks “next”:
    4.1. Increase nextYear value (add 1 to it);
    4.2. Output new nextYear value into corresponding div;

Then let’s think what tools we can use to implement that algorithm:

  1. To store and manipulate with values we can use variables;
  2. To output values there is jQuery’s html() method;
  3. To listen for user clicks there is jQuery’s click() method that you’re already using.

Now, try to implement final solution.
Feel free to ask if you’ll stuck somewhere.

Thanks

@megazoid

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.