fixed pagination bug in javascript