• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

displaying one by one record using servlets

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Iam trying to display records from a database one by one. Iam using servlets to get connection to database embedded with HTML forms to display the record . Iam able to display one record first when screen appears. If i press next button or previous button i should be able to display that record in the same textfields without changing the screen.
Actually onClick function of button iam going to javascript function.Here I donot know what code should i write to display another record. I want the code for next and previous records to be displayed.
Thanks,
vidya
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you don't want to reload the screen, you're going to have to have your form page dynamically generate some javascript for you. I don't have my javascript book with me right now so I'm going to be a little vague, but it should be enough to point you in the right direction.
For the purpose of this discussion we will assume that each row of your result set has only one piece of data, and your form similarly only has one field. Just expand on the ideas i present to accurately reflect your form and data.

  1. Your servlet will have to generate a javascript array containing all the data from your ResultSet. We'll call this array data[].
  2. You will need a global javascript variable to track your current record number, initialized to 0. We'll call this variable recordNum.
  3. You need javascript methods called next() and previous(). These methods increment or decrement recordNum. These methods then call another javascript method displayRecord().
  4. displayRecord() changes the value of the form field to data[recordNum].
  5. Your form has two buttons (next and previous) that call next() and previous().

  6. For more than one item of data you could either have an array for each data item, or even better, a multidimensional array. Hope this helps.
    [This message has been edited by Jason Menard (edited March 27, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic