• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

List View in JSP from database  RSS feed

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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: 506
15
Java Notepad
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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: 506
15
Java Notepad
  • Mark post as helpful
  • send pies
  • 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
  • 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: 506
15
Java Notepad
  • Mark post as helpful
  • send pies
  • 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
  • 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: 506
15
Java Notepad
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code can be something like this:

 
Mayukh Singha Roy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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: 506
15
Java Notepad
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Note: The tables are same...
 
Master Rancher
Posts: 3673
40
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Author and ninkuma
Marshal
Posts: 66820
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!