Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet interrelated two selection box

Have Programming Question? Ask it here!
 
 
 


farooq s
interrelated two selection box
1 Answer(s)      2 years ago
Posted in : JSP-Servlet


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


Advertisement
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
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
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
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
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
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
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
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
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
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
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
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
JTable - Cell selection - Swing AWT
(ListSelectionModel.SINGLE_SELECTION); JScrollPane spane = new JScrollPane(table
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
java swing-action on checkbox selection
java swing-action on checkbox selection  I am working in netbeans and mysql.On selecting a check box, the data from database must be retrieved. i need the action preformance of check box...could nybody?....if could...!thanks
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
Selection Sort In Java
Selection Sort In Java      ... are going to sort the values of an array  using selection sort.In selection sorting.... Sort the remaining  values by using same steps. Selection sort 
Drop-down text selection in jsp/html
Drop-down text selection in jsp/html  Hi, I am trying to create JSP page where I have two drop-downs. There are two-sets of data - First set Categories- Movies, Books, Music and the Second set Genres- Action,Comedy,Romantic
Syntax for image selection Urgent - JSP-Servlet
Syntax for image selection Urgent  Respected Sir/Madam, I am using the following syntax to know whether radio button has been clicked or not: for(var i=0;i  Hi friend, now show the question no 2129 Here
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
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
Importance of Recruitment and Selection
the Recruitment and Selection is the basic significant factors which decides by Human Resource Department of the organization. Recruitment and Selection are one... be choose. On the other hand, Selection is the process where qualifications
Modifying a single row of database based on selection in jsp
Modifying a single row of database based on selection in jsp  Hi guys, i have a problem, I am Fetching the results from database and displaying in a row with s3everal columns, each row having a radio button and a value
select box and text box validations
select box and text box validations  hi, any one please tell me how to set validations for select box and text boxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
Image Selection Reply Urgent.. - JSP-Servlet
Image Selection Reply Urgent..  Respected Sir/Madam, I am R.Ragavendran.. Thanks for yuor fast response.. Sir actually I will be much more convenient if you provide me with coding.. I dont know to work with images as i
dropdown box
dropdown box  i need to have country,state and city in drop down box using ajax and use db2 database   Have a look at the following link: JSP dependent dropdown
Hollow Box
Hollow Box  Write an application program that will draw a hollow box (a box with empty space in between). The program will ask the user to key... to exit. For example, if the user keys in 8, the hollow box (of length and width
Populate listbox according to selection value from another selectbox
Populate listbox according to selection value from another selectbox  ... has different different courses. In registration form i want two select boxes one... listbox from database but campus list box will removes selected value.. please help
Program Arrow selection Most Urgent - JSP-Servlet
Program Arrow selection Most Urgent  Respected Sir/Madam, I am R.Ragavendran.. I got your coding which is highly appreciable.. As per my requiremennt,there are image buttons for each row in the database.. But i am
dialog box
dialog box to ask to quit or continue  hello. write an application that displays a series of at least four interview questions and each question... of the interview, use a dialog box to ask whether the user wants to - enter another set
dialog box
dialog box to show latest question  hello. write an application that displays a series of at least four interview questions and each question should... of the interview, use a dialog box to ask whether the user wants to - enter another set
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
Advertisements
 

 

 

DMCA.com