By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,141 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

Populate textbox fields when selections made in combo box

P: 4
I have a jsp page

these are three formfields
itemsr : --it is a combobox
itemtype : --textfield
itemname : --textfield

to itemsr i have to populate from itemtable(database mysql) and by on change event when the option is changed in itemsr the corresponding itemtype and itemname from the itemtable should be displayed inside the textfield.
I want detail code of it
Nov 7 '07 #1
Share this Question
Share on Google+
5 Replies


acoder
Expert Mod 15k+
P: 16,027
You can't expect someone to do all the work for you.

Post what code you have so far and we can suggest changes.

This has already been asked a number of times. You have two choices: either you want to load everything during page load and use arrays to store the data which is populated dynamically onchange, or you use AJAX to retrieve the data each time from the server.
Nov 7 '07 #2

P: 4
this is my code
Expand|Select|Wrap|Line Numbers
  1. <body>
  2.             <html:form action="/pur">
  3.  
  4.             itemsr : <html:select  property="itemsr">
  5.                        <%try{
  6.             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  7.             Connection con=DriverManager.getConnection("jdbc:odbc:dsn2","root","root");
  8.             Statement st=con.createStatement();
  9.             String sq="select it_sr from bs_invent_items";
  10.  
  11.             ResultSet rs1= st.executeQuery(sq);
  12.  
  13.         while(rs1.next()){
  14.              String s1=rs1.getString(1);
  15.           out.println("<option>"+s1+"</option>");    
  16.           }
  17.            rs1.close();
  18.  
  19.            st.close();
  20.             con.close();
  21.  
  22.         }
  23.         catch(Exception e)
  24.         {
  25.             System.out.println(e);
  26.         }          
  27.              %>
  28.              </html:select><br/> 
  29.  
  30.  
  31.             itemtype : <html:text   title="itemtype" property="itemtype"/><html:errors property="itemtype"/><br/>
  32.             <SCRIPT type="text/javascript">
  33.             try{
  34.             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  35.             Connection con=DriverManager.getConnection("jdbc:odbc:dsn2","root","root");
  36.             Statement st=con.createStatement();
  37.  
  38.              HttpSession ses =request.getSession(true);
  39.   String idd = ses.getValue("id").toString();
  40.  
  41.             String sq="select it_type from bs_invent_items where it_sr='"+idd+"'";
  42.             System.out.println(sq);
  43.             ResultSet rs2= st.executeQuery(sq);
  44.  
  45.         while(rs2.next()){
  46.              String s1=rs2.getString(2);
  47.  
  48.           }
  49.  
  50.  
  51.            rs2.close();
  52.  
  53.            st.close();
  54.             con.close();
  55.  
  56.         }
  57.         catch(Exception e)
  58.         {
  59.             System.out.println(e);
  60.         }   
  61.         document.getElementById("itemtype").innerHTML = "+s1+"; 
  62.  
  63.             </SCRIPT>
  64.  
any i have populated itemsr from the database but by onchange event when the option of the itemsr is changed ,the field itemtype should get the value from database where itemsr is that selected option.

I have taken the value of item sr throug session.session is also notworking .How to put a sessionvariable in javascript
Nov 7 '07 #3

acoder
Expert Mod 15k+
P: 16,027
Do you have any experience or are you willing to learn AJAX?
Nov 7 '07 #4

P: 4
I am very new to ajax therefore i am unable to proceed further
Nov 12 '07 #5

acoder
Expert Mod 15k+
P: 16,027
I am very new to ajax therefore i am unable to proceed further
Have a look at this simple example to get you started. If you have any problems, post again here and we'll try to solve it.
Nov 12 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.