2

I have an external JavaScript file named paging.js. Following are the contents of the file:

function Pager(tableName,itemPerPage){
    this.tableName = tableName;
    this.itemPerPage = itemPerPage;
    this.currentPage = 1;
    this.pages = 0;

    this.init()= function(){
        alert("init called ");
        var rows = document.getElementById(tableName).rows;
        var records = (rows.length - 1);
        this.pages = Math.ceil(records / itemPerPage);
    }

    this.showPageNav = function(pagerName,positionId){
        alert("show page navi call");
        var element = document.getElementById(positionId);
        var pagerHtml = '<input src = "next.jpg" type="image">';
        pagerHtml += '<input src = "next.jpg" type="image">' ;
        element.innerHTML = pagerHtml;
    }
}

Now I tried to call init from my jsp page like .

<script type="text/javascript">
                        var pager = new Pager('results',7);
                        pager.init();
                    </script>

This code i put before complete my body part in my jsp page.

For including this page I put line like

<script type="text/javascript" 
                  src="${pageContext.request.contextPath}/js/paging.js"></script>

But i can't able to call init method. Is there anyone to help me for finding problem?

javanna
  • 59,145
  • 14
  • 144
  • 125
chetan
  • 3,175
  • 20
  • 72
  • 113

3 Answers3

1

This line of code is the problem:

this.init()= function(){

Change it to:

this.init=function() {
icktoofay
  • 126,289
  • 21
  • 250
  • 231
0

With .jsp 2.+ technology, I place all my links and scripts in a separate file that I reference using the <jsp:include> directive:

<jsp:include page="//path to your links_and_scripts page">

My links_and_scripts page has this meta and the path to my script:

<meta http-equiv="Content-Script-Type" content="application/javascript; charset=utf-8" />
<script src="// path to your scripts js"></script>
//...your other scripts and links here
Jules0707
  • 605
  • 7
  • 3
0

Try

<script type="text/javascript" 
                  src="js/paging.js"></script>
Paul
  • 4,812
  • 3
  • 27
  • 38
  • this may not work if the url is `http://baseurl/conextroot/somedir/myjsp.jsp` and JS is just under context root. – Nishant Jan 25 '11 at 07:07