Results 1 to 4 of 4
  1. #1
    Sushanth is offline Member
    Join Date
    Sep 2014
    Posts
    2
    Rep Power
    0

    Cool To get selected value from combobox or dropdown box in jsp

    This is my program to get value from database and display in drop down box and it works perfectly. Now i want to get selected value from drop down box. How should i do it.

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@page import="java.sql.PreparedStatement, java.sql.ResultSet"%>
    <%@page
    import="java.util.ArrayList, java.sql.Connection, java.sql.DriverManager"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Task</title>
    </head>

    <body>

    <%
    java.sql.Statement stmt = null;
    ResultSet rs = null;
    Class.forName("oracle.jdbc.driver.OracleDriver");
    String url = "jdbc:oracle:thin:@CSLC10546.global.chainsys.com:1 521/XE";
    String username = "system";
    String password = "oracle";
    Connection connection = null;
    %>
    Manager Name
    <%
    try {
    ArrayList<String> Mname = new ArrayList<String>();
    connection = DriverManager.getConnection(url, username,
    password);
    stmt = connection.createStatement();
    String query = "Select distinct a.First_Name From Employee_Table a,Employee_Table b where a.Employee_Id=b.Report_To";
    rs = stmt.executeQuery(query);
    while (rs.next()) {
    Mname.add(rs.getString(1));
    }
    log(" value " + Mname);
    request.getSession().setAttribute("Mname", Mname);
    rs.close();
    stmt.close();
    connection.close();
    connection = null;
    } catch (Exception e) {
    e.printStackTrace();
    }
    %>
    <select name="Mname" onChange="getApplicationList(this.form.Mname)">
    <option value=""></option>
    <%
    ArrayList<String> Mname1 = (ArrayList) request.getSession()
    .getAttribute("Mname");
    for (int i = 0; i < Mname1.size(); i++) {
    String selected = "";
    %><option <%=selected%> value=<%=(String) Mname1.get(i)%>><%=Mname1.get(i)%></option>
    <%
    }
    %>
    </select>

    </body>
    </html>

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: To get selected value from combobox or dropdown box in jsp

    What do you want to do with the selected value?
    If it needs processing on the server then you need to send the value to the server, either as part of a <form> or as an Ajax call or similar.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Sushanth is offline Member
    Join Date
    Sep 2014
    Posts
    2
    Rep Power
    0

    Exclamation Re: To get selected value from combobox or dropdown box in jsp

    I use the selected value in a select query and again create a combobox ie "select employee_name from employee_table where = --selected value--".
    The selected value should go into where condition.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: To get selected value from combobox or dropdown box in jsp

    So you'll want to send that value to the server.
    Now you need to decide whether you want a full page refresh, which could be done by submitting that <select> inside a <form>, or make an Ajax call where you then do something with the result. The latter involves Javascript. Both should involve servlets.
    Indeed, your JSP above should have all that Java code stripped out into a servlet.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 2
    Last Post: 11-29-2013, 06:44 AM
  2. Dropdown ComboBox Problem....
    By manners in forum New To Java
    Replies: 3
    Last Post: 09-27-2012, 06:31 PM
  3. ComboBoX dropdown
    By dalu in forum New To Java
    Replies: 6
    Last Post: 04-08-2011, 05:53 AM
  4. set gender and selected combobox value
    By wynects in forum Java Servlet
    Replies: 0
    Last Post: 12-21-2010, 06:03 AM
  5. options already selected from dropdown list based on database request.
    By sauravsinha in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-29-2010, 10:46 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •