title: How do I move to last record of database with a button in JSP, using JavaScript function
body: <p>So i have created a code that display database record into a html textbox and I am able to move to the next record and move back a record using a javascript function that I assign to a button. but i having trouble creating a function that will allow me to move to the last record and a button to move back to the first record.</p>
  
  <pre><code>&lt;%@ page import="java.sql.*" %&gt;
      &lt;% Class.forName("com.mysql.jdbc.Driver");%&gt;
      &lt;HTML&gt;
          &lt;HEAD&gt;
          &lt;/HEAD&gt;
          &lt;BODY&gt;
  
              &lt;FORM NAME="form1" METHOD="POST"&gt;
                  &lt;%
                      int current = 1;
                      if (request.getParameter("hidden") != null) {
                          current = Integer.parseInt(request.getParameter("hidden"));
                      }
                      Connection connection = DriverManager.getConnection("jdbc:mysql://localhost", "root", "symphonia23");
                      Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                      statement.executeQuery("use books");
                      ResultSet resultset = statement.executeQuery("select * from books");
  
                      if (current &lt; 1) {
                          current = 1;
                      }
                      resultset.last();
                      int rows = resultset.getRow();
                      if (current &lt;= rows) {
                          resultset.absolute(current);
                      }
                  %&gt;
  
                  Code: &lt;input type="text" id="code"  value="&lt;%=resultset.getString("BookCode")%&gt;"&gt;&lt;br&gt;
                  Book Title: &lt;input type="text" name="Code" value="&lt;%=resultset.getString("BookTitle")%&gt;"&gt;&lt;br&gt;
                  Book Price: &lt;input type="text" name="Code" value="&lt;%=resultset.getString("BookPrice")%&gt;"&gt;&lt;br&gt;
                  &lt;BR&gt;
  
                  &lt;INPUT TYPE="HIDDEN" NAME="hidden" VALUE="&lt;%= current%&gt;"&gt;
                  &lt;INPUT TYPE="BUTTON" VALUE="Next" ONCLICK="moveNext()"&gt;
                  &lt;INPUT TYPE="BUTTON" VALUE="Prev" ONCLICK="movePrevious()"&gt;
                   &lt;INPUT TYPE="BUTTON" VALUE="First" ONCLICK="movefirst()"&gt;
  
              &lt;/FORM&gt;
  
  
  
  
  
                  &lt;SCRIPT LANGUAGE="JavaScript"&gt;
                      &lt;!--
                  function moveNext()
                      {
                          var counter = 0
                          counter = parseInt(document.form1.hidden.value) + 1
                          document.form1.hidden.value = counter
                          form1.submit()
                      }
                      function movePrevious()
                      {
                          var counter = 0
                          counter = parseInt(document.form1.hidden.value) - 1
                          document.form1.hidden.value = counter
                          form1.submit()
                      }
  
                       function movefirst()
                        {
                          var counter = 0
                          counter = parseInt(document.form1.hidden.value) 
                          document.form1.hidden.value = counter
                          form1.submit()
                      }
  
                      // --&gt; 
              &lt;/SCRIPT&gt;
          &lt;/BODY&gt;
      &lt;/HTML&gt;
  </code></pre>