Populate textbox fields when selections made in combo box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vidyagopal
    New Member
    • Nov 2007
    • 4

    Populate textbox fields when selections made in combo box

    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(datab ase 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
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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.

    Comment

    • vidyagopal
      New Member
      • Nov 2007
      • 4

      #3
      this is my code
      [CODE=java]<body>
      <html:form action="/pur">

      itemsr : <html:select property="items r">
      <%try{
      Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
      Connection con=DriverManag er.getConnectio n("jdbc:odbc:ds n2","root","roo t");
      Statement st=con.createSt atement();
      String sq="select it_sr from bs_invent_items ";

      ResultSet rs1= st.executeQuery (sq);

      while(rs1.next( )){
      String s1=rs1.getStrin g(1);
      out.println("<o ption>"+s1+"</option>");
      }
      rs1.close();

      st.close();
      con.close();

      }
      catch(Exception e)
      {
      System.out.prin tln(e);
      }
      %>
      </html:select><br/>


      itemtype : <html:text title="itemtype " property="itemt ype"/><html:errors property="itemt ype"/><br/>
      <SCRIPT type="text/javascript">
      try{
      Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
      Connection con=DriverManag er.getConnectio n("jdbc:odbc:ds n2","root","roo t");
      Statement st=con.createSt atement();

      HttpSession ses =request.getSes sion(true);
      String idd = ses.getValue("i d").toString ();

      String sq="select it_type from bs_invent_items where it_sr='"+idd+"' ";
      System.out.prin tln(sq);
      ResultSet rs2= st.executeQuery (sq);

      while(rs2.next( )){
      String s1=rs2.getStrin g(2);

      }


      rs2.close();

      st.close();
      con.close();

      }
      catch(Exception e)
      {
      System.out.prin tln(e);
      }
      document.getEle mentById("itemt ype").innerHTM L = "+s1+";

      </SCRIPT>
      [/CODE]
      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
      Last edited by acoder; Nov 7 '07, 09:25 AM. Reason: Added code tags

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Do you have any experience or are you willing to learn AJAX?

        Comment

        • vidyagopal
          New Member
          • Nov 2007
          • 4

          #5
          I am very new to ajax therefore i am unable to proceed further

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by vidyagopal
            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.

            Comment

            Working...