title: calling javascript function with parameters in href
body: <p>I am working on a pagination project. I need to create a pagination function, which will pass the page number and execute the getData(page) function to get page data and display. However, I got undefined with my page number.</p>
  <pre><code>&lt;script&gt;
  $(document).ready(function() {
    var firstPage = &quot;${firstPage}&quot;;
    var lastPage = &quot;${lastPage}&quot;;
    var currentPage = &quot;${currentPage}&quot;;
    var totalPage = &quot;${totalPage}&quot;;
    setPagination(firstPage, lastPage, currentPage, totalPage);
  });
  
  function setPagination(firstPage, lastPage, currentPage, totalPage) {
    var paginationHTML = &quot;&quot;;
    if (currentPage != 1) {
      paginationHTML = paginationHTML + '&lt;a href=&quot;#&quot; onclick=&quot;getData(1);&gt;|&amp;lt;&lt;/a&gt;';
      paginationHTML = paginationHTML + '&lt;a href=&quot;#&quot; onclick=&quot;getData(parseInt(currentPage)-1);&gt;&amp;lt;&lt;/a&gt;';
    }
    for (var i = parseInt(firstPage); i &lt;= parseInt(lastPage); i++) {
      if (i == currentPage) {
        paginationHTML = paginationHTML + '&lt;a href=&quot;#&quot; onclick=&quot;getData(i); class=&quot;active&quot;&gt;' + i + '&lt;/a&gt;';
      } else {
        paginationHTML = paginationHTML + '&lt;a href=&quot;#&quot; onclick=&quot;getData(i);&gt;' + i + '&lt;/a&gt;';
      }
    }
    if (currentPage != lastPage) {
      paginationHTML = paginationHTML + '&lt;a href=&quot;#&quot; onclick=&quot;getData(parseInt(currentPage)+1);&gt;&amp;gt;&lt;/a&gt;';
      paginationHTML = paginationHTML + '&lt;a href=&quot;#&quot; onclick=&quot;getData(totalPage);&gt;&amp;gt;|&lt;/a&gt;';
    }
  
    $(&quot;.pagination&quot;).append(paginationHTML);
  }
  </code></pre>