• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
Bartenders:
  • Himai Minh
  • Carey Brown
  • Frits Walraven

How do I move to last record of database with a button in JSP, using JavaScript function

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Sheriff
Posts: 67557
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Before we even get to the JavaScript, your page has some serious problems. First and foremost it will break badly when more than one user starts to use your application because you have used scriptlet declarations within the page.

One of the very many reasons that scriptlets were obsoleted and discredited over 12 years ago was just this very type of problem. Java code should be in a Java class and never in a JSP.

I can tell from the way that you've written your HTML, JavaScript, and other elements that you are using some very old references. I'd highly advise adopting more recent reference material.
 
author & internet detective
Posts: 40683
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, even supposing all that was in a Java class, there is still a problem. The query is being done each time so it doesn't make sense to talk about going to the first/last part. It would make sense to have a button control the sorting or paging of the result. Which would be passed to the query to change/limit the results.
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the sort of thing that DataTables was made for. And Bear and Jeanne are offering you critical advice; pay heed. You are headed down a long, ugly road with the style of coding that you are using. Your jsp should end up looking something like this:


This is just an example from one of my pages; it's not meant to address your question directly. But notice that there are no scriplets and no database functions in the page. All that belongs at another layer. A servlet calls a DAO which manages the database functions. Jquery, AJAX and DataTables build the page components and insert them when and where needed. A different servlet handles exporting to Excel.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic