最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Calculating records per page - Stack Overflow

programmeradmin2浏览0评论

Hi I am new to javascript. The formula that I am using for my application is calculating the wrong last page number. How it works is when a user enter the page range they want printed it should only print the page range from the start page to the end page. User inputs are first page and last page. Thank you very much

    var rn = parseInt($('reportNumber').value) ;
    var s = parseInt($('startpage').value) ;
    var e = parseInt($('endpage').value) ;
    var l = parseInt($('linesPerPage').value) ;
    var i = (((e-s)+1)*l) ; // calculating the total number of records per page 
    createReport(rn,s,i) 

In another function I am doing this for pagination:

   lastpage = Math.ceil(TotalNumberOfRows/recordsPerPage) ;

Hi I am new to javascript. The formula that I am using for my application is calculating the wrong last page number. How it works is when a user enter the page range they want printed it should only print the page range from the start page to the end page. User inputs are first page and last page. Thank you very much

    var rn = parseInt($('reportNumber').value) ;
    var s = parseInt($('startpage').value) ;
    var e = parseInt($('endpage').value) ;
    var l = parseInt($('linesPerPage').value) ;
    var i = (((e-s)+1)*l) ; // calculating the total number of records per page 
    createReport(rn,s,i) 

In another function I am doing this for pagination:

   lastpage = Math.ceil(TotalNumberOfRows/recordsPerPage) ;
Share Improve this question edited Dec 10, 2013 at 18:48 Peter H asked Dec 10, 2013 at 18:36 Peter HPeter H 311 silver badge3 bronze badges 7
  • 1 What JS library are you using? In jQuery, it should be $('#reportNumber') and so on -- you need # before the ID in selectors. – Barmar Commented Dec 10, 2013 at 18:42
  • Why do you need to calculate records per page? Isn't that what l is? – Barmar Commented Dec 10, 2013 at 18:53
  • I am using JQuery 1.9.1 – Peter H Commented Dec 10, 2013 at 18:54
  • Then you need to add # before all the IDs in the selectors. – Barmar Commented Dec 10, 2013 at 18:56
  • That part of the code works fine – Peter H Commented Dec 10, 2013 at 19:38
 |  Show 2 more ments

1 Answer 1

Reset to default 7

You're dividing by the total number of rows in the page range, you should divide by the number of rows per page.

lastpage = Math.ceil(TotalNumberOfRows/l);
发布评论

评论列表(0)

  1. 暂无评论