How to calculate previous month value in DHIS2 data entry form?

dhis2.util.on( 'dhis2.de.event.formReady', function( event,iReVg2xgFPL ) {
      var periodN= $( '#selectedPeriodId' ).val();// From DHIS2 Selection Param
      var nextPeriod=(+periodN) + (+1);//201611,201612,201613
      var nextPeriodSeperate=periodN.toString().substring(0, 4);
      var year=parseInt(nextPeriodSeperate.trim());
      var month=parseInt(periodN % 100);
      if(month==12){
        year++;
        month=01;
        nextPeriod=year+'01';   
      }   
     $('.selectedDate').val(nextPeriod);
});
See detail: http://dhis2trainingland.com/eportal/?tutorial=how-to-calculate-previous-month-value-in-dhis2-data-entry-form