interrelated two selection box

interrelated two selection box

hi i need two selection box .in 1 box all designation like manager, ceo etc , onclick on manager i should get list of managers names in second selection box.. like wise so on. from database eg: manager: sanjay ,amir , ram , mohan CEO: deepak , farooq

View Answers

August 28, 2012 at 6:08 PM

Here is a jsp application that retrieves data from the database and stored into first dropdown. If user click any option from the dropdown, the corresponding values will get displayed into another dropdown.

1)selDesg.jsp:

<%@page import="java.sql.*"%>
 <html>
      <head>  
      <script language="javascript" type="text/javascript">  
      var xmlHttp  
      var xmlHttp
      function showEmp(str){
      if (typeof XMLHttpRequest != "undefined"){
      xmlHttp= new XMLHttpRequest();
      }
      else if (window.ActiveXObject){
      xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
      }
      if (xmlHttp==null){
      alert("Browser does not support XMLHTTP Request")
      return;
      } 
      var url="selEmp.jsp";
      url +="?count=" +str;
      xmlHttp.onreadystatechange = stateChange;
      xmlHttp.open("GET", url, true);
      xmlHttp.send(null);
      }

      function stateChange(){   
      if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){   
      document.getElementById("emp").innerHTML=xmlHttp.responseText   
      }   
      }
      </script>  
      </head>  
      <body>  
      <select name='desg' onchange="showEmp(this.value)">  
       <option value="none">Select</option>  
    <%
 Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
 Statement stmt = con.createStatement();  
 ResultSet rs = stmt.executeQuery("Select * from desg");
 while(rs.next()){
     %>
      <option value="<%=rs.getString("DESG_NO")%>"><%=rs.getString("DESIGNATION")%></option>  
      <%
 }
     %>
      </select>  
      <br>  
      <div id='emp'>  
      <select name='emp' >  
      <option value='-1'></option>  
      </select>  
      </div>  
      </body> 
      </html>

2)selEmp.jsp:

<%@page import="java.sql.*"%>
<%
String no=request.getParameter("count");  
 String buffer="<select name='emp' ><option value='-1'>Select</option>";  
 try{
 Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
 Statement stmt = con.createStatement();  
 ResultSet rs = stmt.executeQuery("Select * from emp where DESG_NO='"+no+"' ");  
   while(rs.next()){
   buffer=buffer+"<option value='"+rs.getString("EMP_NAME")+"'>"+rs.getString("EMP_NAME")+"</option>";  
   }  
 buffer=buffer+"</select>";  
 response.getWriter().println(buffer); 
 }
 catch(Exception e){
     System.out.println(e);
 }
 %>

For the above code, we have used two database tables:

1)desg:

CREATE TABLE `desg` (                     
          `DESG_NO` int(100) default NULL,        
          `DESIGNATION` varchar(255) default NULL   
        );

2)emp:

CREATE TABLE `emp` (                                      
          `EMP_NO` int(10) NOT NULL auto_increment,               
          `EMP_NAME` varchar(100) default NULL,                   
          `DESIGNATION` varchar(100) default NULL,                
          `JOINING_DATE` date default NULL,                       
          `SALARY` int(100) default NULL,                         
          `DESG_NO` int(100) default NULL,                        
          `DEPT_NAME` varchar(100) default NULL,                  
          PRIMARY KEY  (`EMP_NO`)                                 
        );









Related Tutorials/Questions & Answers:
interrelated two selection box
interrelated two selection box  hi i need two selection box .in 1 box all designation like manager, ceo etc , onclick on manager i should get list of managers names in second selection box.. like wise so on. from database
selection box linked with textarea
selection box linked with textarea    function get_val(tot_val1) { document.getElementById('TextBox1').value = tot_val1; alert(tot_val1... detals i have in db with all fields .. like wise i have names in selection box sham
Advertisements
enable text box and label on selection
enable text box and label on selection  hello, Please tell me how to enable label and text box on selection of drop down list box. in drop down list box all values come from database. please reply
two text box problem
two text box problem  i have two text box in two different pages and same variable use in two text box when enter value in first text box it's reflection show in second text box , how i reduce it in jsf ?   Hi Friend
radio button selection should move the control to a text box that needs to be complete
radio button selection should move the control to a text box that needs to be complete  on selection of a radio button mouse should move to a particular text box that needs to be filled. How
my table should be reseted to new value upon the selection of the combo box..
my table should be reseted to new value upon the selection of the combo box..  import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.sql.Connection
How to show autocomplete textbox values on combo box option selection using database?
How to show autocomplete textbox values on combo box option selection using database?  When I select option(i.e First Year) then it will show list of student names in auto-complete text box
Display two alert box alternately by clicking on text
Display two alert box alternately by clicking on text In this tutorial , we will discuss about how to display two alert box alternately by clicking on text... on it ,it will show a alert box. But when we click on it again , it shows second alert box
display diffrence between two dates in a text box - JSP-Servlet
display diffrence between two dates in a text box  i have these set of codes // String di=request.getParameter("timestamp2"); String d2... the days in another text box when i click inside that test box.lease help me
sir plz help in design a jsp page whichis as follow username [_____] select [__>]password [_____] after selection then onlypassword text box is visible
sir plz help in design a jsp page   sir plz help in design a jsp page which is as follow username [ _ ] select [ > ] password [ _ ] after selection then only password text box is visible
Help With Costructing Selection sort?
Help With Costructing Selection sort?  Using a selection sort... separated by : (colon) sorted by the first dimension. I got the two dimensional array... in advance!   Please visit the following link: Java Selection Sort
Selection based on other selection in jsp
Selection based on other selection in jsp  I am trying to create a jsp page. Where I am having a select list containing category name and for each... selection on same jsp page such that when someone select a category only the products
checkbox selection in jsp
checkbox selection in jsp  hey guys i am working on a web based... form. I want to select i check box from each row and also i want to avoid many check box in the same row. How can i get this one working? Can anyone help me
Selection Using JoptionPane
Selection Using JoptionPane  Help, can someone provide me the code using JOptionPane for the following:- Part A 1) Prompt user to make 3 selection... to quit, display the total cost of the two items; otherwise, display the total
insert multiple selection - Java
insert multiple selection - Java  how to insert multiple selection values from html into database using servlets
ModuleNotFoundError: No module named 'selection'
ModuleNotFoundError: No module named 'selection'  Hi, My Python... 'selection' How to remove the ModuleNotFoundError: No module named 'selection' error? Thanks   Hi, In your python environment you
Displaying files on selection of date.
Displaying files on selection of date.  Hi, I am developing a GUI, where i select from and to date. On selection of from and to date the GUI should... for same.   Here is a java swing code that accepts two dates and search
Selection With Ajax and JSP
Selection With Ajax and JSP  I am working at a jsp page using ajax for country , state, city selection. so if he select country it will populate the state and city selection (both). After selecting country if he select city
two linked combobox
two linked combobox  give jsp example of two combo box when i select state in one combobox in second combo box cities will display according to state which i select
highlight uitableviewcell on selection
the UITableViewCell on selection in my application.   UITableViewCell... highlight it or use the default selection for the cell in UITableView. Also you can disable the the stye by setting StyleNone to cell selection. But in case
Image Selection - Swing AWT
Image Selection  Hi, I need to provide the image selection facility...; JButton saveButton; public DisplayImage() { super("Image Selection program... { String selection = (String)comboBox.getSelectedItem(); String
changing selection color of <button>
changing selection color of   dear all, i have loaded image in border less button tag when button is selected with tab key i get brown color rectangle around image. how do i change color of that rectangle from brown to white
ModuleNotFoundError: No module named 'causal-selection'
ModuleNotFoundError: No module named 'causal-selection'  Hi, My... named 'causal-selection' How to remove the ModuleNotFoundError: No module named 'causal-selection' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'model-selection'
ModuleNotFoundError: No module named 'model-selection'  Hi, My... named 'model-selection' How to remove the ModuleNotFoundError: No module named 'model-selection' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'model-selection'
ModuleNotFoundError: No module named 'model-selection'  Hi, My... named 'model-selection' How to remove the ModuleNotFoundError: No module named 'model-selection' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'blacken-selection'
ModuleNotFoundError: No module named 'blacken-selection'  Hi, My... named 'blacken-selection' How to remove the ModuleNotFoundError: No module named 'blacken-selection' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'causal-selection'
ModuleNotFoundError: No module named 'causal-selection'  Hi, My... named 'causal-selection' How to remove the ModuleNotFoundError: No module named 'causal-selection' error? Thanks   Hi, In your
else if (selection = * 'M'); - Java Beginners
else if (selection = * 'M');  I am trying to get 2 numbers 2... if (selection = * 'M'); ^ this is my program - what am i...; System.out.print("Enter A(dd), S(ubtract), M(ultiply):"); selection = (char
combo box
combo box  Hi, [_|] dropdown box... a screen like this using jsp-servlet(or DAO,DTO),in that drop down box i should get usernames from the database & upon selection of particular user i should get
single selection of chechbox among multiple selection when in a loop.
single selection of chechbox among multiple selection when in a loop.  i am using cmd prompt to run and execute the java pgm. here i need your help... but here am getting multiple selection(previous selected item also coming again
ModuleNotFoundError: No module named 'box-box'
ModuleNotFoundError: No module named 'box-box'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'box-box' How to remove the ModuleNotFoundError: No module named 'box-box
ModuleNotFoundError: No module named 'box-box'
ModuleNotFoundError: No module named 'box-box'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'box-box' How to remove the ModuleNotFoundError: No module named 'box-box
How to cascade two text boxes??
How to cascade two text boxes??  I am having 3 text boxes if i entered the value in the first text box then the values of the two text boxes should come from the database with respect to first text box value
HTML in the box
HTML in the box  Can I use any HTML in the box
input box
input box  give me the code of input box in core java
input box
input box  give me the code of input box in core java
Selection Sort in Java
Selection sort in Java is used to sort the unsorted values in an array. In selection sorting algorithm, the minimum value in an array is swapped... position. This procedure is repeated till the array is sorted completely. Selection
ModuleNotFoundError: No module named 'colcon-package-selection'
ModuleNotFoundError: No module named 'colcon-package-selection'  Hi...: No module named 'colcon-package-selection' How to remove the ModuleNotFoundError: No module named 'colcon-package-selection' error? Thanks  
ModuleNotFoundError: No module named 'ecg-feature-selection'
ModuleNotFoundError: No module named 'ecg-feature-selection'  Hi...: No module named 'ecg-feature-selection' How to remove the ModuleNotFoundError: No module named 'ecg-feature-selection' error? Thanks   Hi
ModuleNotFoundError: No module named 'naive-feature-selection'
ModuleNotFoundError: No module named 'naive-feature-selection'  Hi...: No module named 'naive-feature-selection' How to remove the ModuleNotFoundError: No module named 'naive-feature-selection' error? Thanks   
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection'
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' ...: No module named 'odoo10-addon-pos-lot-selection' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' error
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection'
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' ...: No module named 'odoo10-addon-pos-lot-selection' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' error
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection'
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' ...: No module named 'odoo10-addon-pos-lot-selection' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' error
ModuleNotFoundError: No module named 'odoo11-addon-pos-lot-selection'
ModuleNotFoundError: No module named 'odoo11-addon-pos-lot-selection' ...: No module named 'odoo11-addon-pos-lot-selection' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-pos-lot-selection' error
ModuleNotFoundError: No module named 'rpi-feature-selection-toolbox'
ModuleNotFoundError: No module named 'rpi-feature-selection-toolbox'  ...: No module named 'rpi-feature-selection-toolbox' How to remove the ModuleNotFoundError: No module named 'rpi-feature-selection-toolbox' error
ModuleNotFoundError: No module named 'branch-and-bound-feature-selection'
ModuleNotFoundError: No module named 'branch-and-bound-feature-selection' ...: ModuleNotFoundError: No module named 'branch-and-bound-feature-selection' How to remove the ModuleNotFoundError: No module named 'branch-and-bound-feature-selection
ModuleNotFoundError: No module named 'colcon-package-selection'
ModuleNotFoundError: No module named 'colcon-package-selection'  Hi...: No module named 'colcon-package-selection' How to remove the ModuleNotFoundError: No module named 'colcon-package-selection' error? Thanks  
ModuleNotFoundError: No module named 'ecg-feature-selection'
ModuleNotFoundError: No module named 'ecg-feature-selection'  Hi...: No module named 'ecg-feature-selection' How to remove the ModuleNotFoundError: No module named 'ecg-feature-selection' error? Thanks   Hi
ModuleNotFoundError: No module named 'feature-selection-fdr'
ModuleNotFoundError: No module named 'feature-selection-fdr'  Hi...: No module named 'feature-selection-fdr' How to remove the ModuleNotFoundError: No module named 'feature-selection-fdr' error? Thanks   Hi
ModuleNotFoundError: No module named 'knock-feature-selection'
ModuleNotFoundError: No module named 'knock-feature-selection'  Hi...: No module named 'knock-feature-selection' How to remove the ModuleNotFoundError: No module named 'knock-feature-selection' error? Thanks   

Ads