• 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
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

List View in JSP from database

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In JSP I have made a list containing items from database. Now I want to display it's details(taken from database)in a textbox whenever a particular list item is selected.

Code done till now



here in last part i want to display it in div class that input text box..

Help me..``
 
Rancher
Posts: 517
15
Notepad Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So far what are you able to do? Are you seeing the list items in the select list ?

That  Java code within JSP is mostly not allowed nowadays, and not a good programming practice.
 
Mayukh Singha Roy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Saya wrote:So far what are you able to do? Are you seeing the list items in the select list ?

That  Java code within JSP is mostly not allowed nowadays, and not a good programming practice.



I can view the list items in the select list but i want display that in an input box..
 
Prasad Saya
Rancher
Posts: 517
15
Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the <select> tag there is an attribute named "onchange".  Call a javascript function from "onchange" which will fill the textbox with the selected item in the list.
 
Mayukh Singha Roy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Saya wrote:For the <select> tag there is an attribute named "onchange".  Call a javascript function from "onchange" which will fill the textbox with the selected item in the list.



<select ="onchange">
   <%  while(resultset.next()){ %>
       <option><%= resultset.getString(1)%>  <%= resultset.getString(2)%></option>
   <% } %>
<% function onchange
     {
      }
     %>
   </select>


LIKE THIS??
 
Prasad Saya
Rancher
Posts: 517
15
Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No.

Do some google search about getting a value from a html select, etc.
 
Mayukh Singha Roy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Saya wrote:No.

Do some google search about getting a value from a html select, etc.


Can you write the code ... then i can understand
 
Prasad Saya
Rancher
Posts: 517
15
Notepad Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code can be something like this:

 
Mayukh Singha Roy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Saya wrote:The code can be something like this:



Thanks mate but now i am stuck in the function... Suppose in an input box named "item" i want to display it... Then what will i write in code??
 
Prasad Saya
Rancher
Posts: 517
15
Notepad Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The javascript function's code can be like this:

One can get the selected item's index and the value and assign to the textfield.
Find the <select> list element by its id "items"
Get the list selected value based on the index
Find the <input> text element by its id
Assign/set the list selected value to the text element.

In case you have never used javascript you have to get familiar with it and write the code - there are lots of resources on the web if you lookup.
 
Mayukh Singha Roy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Saya wrote:The javascript function's code can be like this:

One can get the selected item's index and the value and assign to the textfield.
Find the <select> list element by its id "items"
Get the list selected value based on the index
Find the <input> text element by its id
Assign/set the list selected value to the text element.

In case you have never used javascript you have to get familiar with it and write the code - there are lots of resources on the web if you lookup.


.
.
.
...
   Statement statement = connection.createStatement() ;

      resultset =statement.executeQuery("select * from item") ;
%>
<select id="items" onchange="display_selection()">
       <%  while(resultset.next()){ %>
           <option><%= resultset.getString(1)%>  <%= resultset.getString(2)%></option>
       <% } %>
       <script>
       function display_selection ()
       {
           <need to write here>
       }
       </script>
       </select>

i have written upto this... Now tell me what to write.. I dont get the javascript terms
 
Mayukh Singha Roy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note: The tables are same...
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember to always think in terms of what is on the server and what is available in the browser.

These are two different locations and, unless all the data is supplied to the browser on the initial response (ie all the values in the drop down as well as all their details) then the browser will have to make another request to the server when the user selects an option, in order to get that data.

That's where Ajax comes into it.
 
Mayukh Singha Roy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Remember to always think in terms of what is on the server and what is available in the browser.

These are two different locations and, unless all the data is supplied to the browser on the initial response (ie all the values in the drop down as well as all their details) then the browser will have to make another request to the server when the user selects an option, in order to get that data.

That's where Ajax comes into it.


i dont know ajax... You just solve my problem... I will be thankful to you
 
Sheriff
Posts: 67746
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
Then it is apparently time to learn about Ajax. That is the way to make a request back to the server without the need to reload the page.

Also, in future posts, please be sure to UseCodeTags when posting code. Thanks.
 
What's brown and sticky? ... a stick. Or a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic