Updated javascript for pagination