Combo Box in JSP

Hi,
I am a student and working on a class project. In my application at some point, I need to provide a combo box where user can select multiple values and those values should automatically be printed in a text area provided below the combo box. Is this possible?

The Only Way By which U can achieve this is by a scripting languages like javascript,vbscript......
Nvr By JSP(Is nothing but a servlet under execution @ background of webserver) as it is meant for Server Side Programming Surely not for Client Side Dynamic Action.
Make use of <select> with multiple property set to true....
and then.... append selected values in the second textbox.
You may go throgh the code given below
c whether that can help u out.....
CLIENT.JSP
=========
<%@ page language="JAVA">
<html>
<head>
<script>
function change(){
var x=document.getElementById("mySelect")
document.getElementById("result").value = ""
for(var i=0;i < x.length;i++){
if(x.options.selected == true)
document.getElementById("result").value = document.getElementById("result").value + " "+x.options[i].value
</script>
</head>
<body>
<select id="mySelect" size="4" multiple onchange="change()">
<option value='Apple'>Apple</option>
<option value='Pear'>Pear</option>
<option value='Banana'>Banana</option>
<option value='Orange'>Orange</option>
</select>
<input type='text' value='' size='10' name='result' id="result">
</body>
</html>
REGARDS,
RaHuL

Similar Messages

  • Combo box in jsp : implemented by struts tiles

    Hi,
    I have few problems with JSP...
    we have devided the body part in the tiles into two parts
    initially..................
    body1: jsp with combo box
    body2: a blank jsp
    if the user selects an option from the combo box..in onchange function ..iam getting the value of the selected option..and iam doing form.action="action selected by user" ... so that it will go the struts-config then inturn will call the action then by forwarding success..will go to the struts-config file again ..then by have name="seccess".. it will call path="somedefinition"....this definition is defined in the tiles-definition file...
    where again...extending some standard definition by overriding ..
    body1:jsp with combo box
    body2:jsp related to the selected option..in the combo box
    second time.. in body1: again we r calling original jsp na..it will show default select only na??
    so how to get the selected option and how i can give that option as selected when it is loading second time.
    Hope you got my problem...
    Please help me out...
    Waiting for ur kind reply
    Thanks & Regards
    Kranti Kiran Kumar Parisa
    Software Engineer [ e-Biz ]
    [email protected]

    It's not nice to highjack someone elses thread. I posted a reply http://forum.java.sun.com/thread.jsp?forum=45&thread=552915 (though I shouldn't have, shoulda done it here). if you have questions post them to this thread instead. Leave the other one to the OP's question.

  • Problem regarding Combo boxes in JSP

    Hi all,
    I have two combo boxes on jsp page, i want to fill the second CB by value of first CB, and both CBs have values from Database, i tried it many times but cant got solution
    plz help me its very urgent and if possible provide code plz
    thanks

    http://forum.java.sun.com/thread.jspa?threadID=597553

  • How to get value of html combo box (i.e select) in jsp?

    Hello,
    I was just wondering how to get value of html combo box in jsp page. My code for combo box is:
    <select name="combo" size="1">
    <%
    List<Project> projects = mgr.getProjects();
    for(Project project : projects){
    %>
    <option value="<%= project.getId()%>"><%= project.getName()%></option>
    <%
    %>
    </select>
    I thought combo.value might give me the value, but it throws exception.
    Any help is appreciated.
    Thanks.

    The combo does not exists in Java, but only in HTML. You have to submit the form containing the combo and then use request.getParameter("combo") to get it's value ;-)

  • How can we pass selected combo box value to a jsp pag?

    Hi All,
    I want to pass selected combo box value to a same jsp page's variable.
    i am using javascript
    <select onchange="this.options[this.selectedIndex].text">
    </select>
    this selected value should be invoked for a jsp page's variable.
    Excepting for favorable reply
    Vansh

    select2.jsp
    <script>
    function x()
         alert(document.f.s.options[document.f.s.selectedIndex].text);
         document.f.submit();
    </script>
    <body>
    <form method="get" name="f" action="select2.jsp">
    <select name="s" onchange="x()">
    <option checked>--select--</option>
    <option value="1"> vijay </option>
    <option value="2"> kumar </option>
    </select>
    </form>
    </body>

  • JSP Combo box question

    How can I make a combo box have the ability to add new items in its list? I have an existing combo box that gets its value from an SQL query. How can I let users have the ability to add to that list? If this is not possible with JSP combo boxes, any suggestions as to what field I may use? Thanks

    Hello Russ9754!
    Might be abit late, but I just read this thread.
    Anyway...I think I have what you are looking for.
    This code creates a dropdown box with the alternatives of your choice. If none of the options is good enough for the user, he/she can choose "other" and enter a more suitable choice in a pop-up javascriptprompt.
    <FORM NAME="formName">
    <SELECT NAME="country" onChange="countryOnChange();">
    <OPTION VALUE="Albania" selected>- = Albania = -</OPTION>
    <OPTION VALUE="Finland">- = Finland = -</OPTION>
    <OPTION VALUE="USA">- = USA = -</OPTION>
    <OPTION VALUE="Other"> Other... </
    OPTION>
    </SELECT>
    </FORM>
    <SCRIPT>
    function countryOnChange(){
    sel = document.formName.country.selectedIndex;
    val = document.formName.country.options[sel].
    value;
    len = document.formName.country.length;
    if (val == "Other"){
    var newcountry = prompt("Enter your country.", "");
    if (newcountry == null) { return; }
    document.formName.country.options[sel].text = newcountry;
    document.formName.country.options[sel].value = newcountry;
    document.formName.country.length = len +1;
    document.formName.country.options[len].text = "Other...";
    document.formName.country.options[len].value = "Other";
    </SCRIPT>

  • Horizontal scroll bar for combo/lsit box in JSP

    hi,
    i want "Horizontal Scroll bar" for combo box to display long names.
    regards,
    krishna

    Not a JSP issue. Look up styles, CSS, and dynamic HTML. They should help.

  • How to populate the combo boxes that are created dynamically in jsp

    Hi,
    I am using JSP.
    I am creating combo boxes dynamically (based on the num selected by the user). These dynamically created combo boxes need to have A-Z as options (each box) . Now, when the user chooses the option A in any of the combo-boxes,the rest should not have this option. so on..
    how do i achieve this.Kindly help.

    You'll need to use JavaScript...I have a complicated example and a simple example, however, I cannot really understand the complex example but I know how it works. The looping is too complex for me.
    First you'll need to populate a server side variable...depending on how often the data is updated you may want this to run each time a new session is created...this example is run each time Tomcat is started and the application context is initialized:
    package kms.web;
    // Servlet imports
    import javax.servlet.ServletContextListener;
    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContext;
    // utility imports
    import java.util.Map;
    // domain imports
    import kms.domain.LocationService;
    import kms.domain.DeptService;
    import kms.domain.PatentService;
    * This listenter is used to initialize
    * the Maps of Locations, Patents & Depts used to populate
    * pulldown lists in JSPs
    public class InitializeData implements ServletContextListener {
        * This method creates the Maps.
       public void contextInitialized(ServletContextEvent sce) {
          ServletContext context = sce.getServletContext();
          LocationService lServ = new LocationService();
          // Create the Maps
          Map campuses = lServ.getCampuses();
          Map buildings = lServ.getBuildings();
          Map floors = lServ.getFloors();
          Map locs = lServ.getLocations();
          // And store them in the "context" (application) scope
          context.setAttribute("campuses", campuses);
          context.setAttribute("buildings", buildings);
          context.setAttribute("floors", floors);
          context.setAttribute("locs", locs);
          DeptService dServ = new DeptService();
          Map depts = dServ.getDepts();
          context.setAttribute("depts", depts);
          PatentService pServ = new PatentService();
          Map patents = pServ.getPatents();
          context.setAttribute("patents", patents);
          //I did this one myself
    /*    CodeService cServ = new CodeService();
          Map masterMks = cServ.getCodes();
          context.setAttribute("masterMks", masterMks);
        * This method is necessary for interface.
       public void contextDestroyed(ServletContextEvent sce) {
       // I have no clue what the heck this is for???
       // Let me know if you do!
    }So now we travel into the PatentService method called 'getPatents();' which in turn calls a PatentDAO method
    Map patents = pServ.getPatents();
    Below is the code for the PatentService object:
    package kms.domain;
    import kms.util.ObjectNotFoundException;
    import java.util.*;
    * This object performs a variety of dept services, like retrieving
    * a dept object from the database, or creating a new dept object.
    public class PatentService {
       * The internal Data Access Object used for database CRUD operations.
      private PatentDAO patentDAO;
       * This constructor creates a Dept Service object.
      public PatentService() {
        patentDAO = new PatentDAO();
    public Map getPatents() {
          Map patents = null;
          try {
            patents = patentDAO.retrieveAll();
          // If the dept object does not exist, simply return null
          } catch (ObjectNotFoundException onfe) {
            patents = null;
          return patents;
    }It may be useful for you to see the code of the Patent class:
    package kms.domain;
    /*** This domain object represents a dept.
    public class Patent implements java.io.Serializable {
      private int codeGgm;
      private String name = "";
      private String description = "";
      private int creator;
      private String creationDate = "";
      private int used;
       * This is the full constructor.
      public Patent(int codeGgm, String name, String desc, int creator, String creationDate, int used) {
        this.codeGgm = codeGgm;
        this.name = name;
        this.description = desc;
        this.creator = creator;
        this.creationDate = creationDate;
        this.used = used;
      public Patent() { }
      public int getCodeGgm() {
          return codeGgm;
      public void setCodeGgm(int codeGgm) {
           this.codeGgm = codeGgm;
      public String getName() {
        return name;
      public void setName(String name) {
          this.name = name;
      public String getDesc() {
        return description;
      public void setDesc(String desc) {
          this.description = desc;
      public int getCreator() {
          return creator;
      public void setCreator(int creator) {
             this.creator = creator;
      public String getCreationDate() {
          return creationDate;
      public void setCreationDate(String creationDate) {
             this.creationDate = creationDate;
      public int getUsed() {
           return used;
      public void setUsed(int used){
           this.used = used;
    }And here is the Database table which stores the Patents:
    DESC PATENT:
    CODE_GGM NUMBER(3)
    NAME VARCHAR2(15)
    DESCRIPTION VARCHAR2(250)
    CREATOR NUMBER(10)
    CREATION_DATE DATE
    USED NUMBER(1)
    So, we then travel into the code of the PatentDAO to see how the DAO object executes the DB query to get all of the Data we need for the select list:
    package kms.domain;
    import javax.naming.*;
    import javax.sql.*;
    import java.util.*;
    import java.sql.*;
    import kms.util.*;
    * This Data Access Object performs database operations on Patent objects.
    class PatentDAO {
       * This constructor creates a Patent DAO object.
       * Keep this package-private, so no other classes have access
    PatentDAO() {
    * This method returns a Map of all the Dept names
    * The key is the Dept id
    Map retrieveAll()
           throws ObjectNotFoundException {
          Connection connection = null;
          ResultSet results = null;
          // Create the query statement
          PreparedStatement query_stmt = null;
          try {
            // Get a database connection
          Context initContext = new InitialContext();
           DataSource ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/keymanOracle");
           connection = ds.getConnection();
            // Create SQL SELECT statement
            query_stmt = connection.prepareStatement(RETRIEVE_ALL_NAMES);
            results = query_stmt.executeQuery();
            int num_of_rows = 0;
          Map patents = new TreeMap();
             // Iterator over the query results
            while ( results.next() ) {
                patents.put(new Integer(results.getInt("code_ggm")), results.getString("name"));
             if ( patents != null ) {
                      return patents;
                    } else {
                      throw new ObjectNotFoundException("patent");
           // Handle any SQL errors
         } catch (SQLException se) {
            se.printStackTrace();
           throw new RuntimeException("A database error occured. " + se.getMessage());
        } catch (NamingException se) {
          throw new RuntimeException("A JNDI error occured. " + se.getMessage());
          // Clean up JDBC resources
          } finally {
            if ( results != null ) {
              try { results.close(); }
              catch (SQLException se) { se.printStackTrace(System.err); }
            if ( query_stmt != null ) {
              try { query_stmt.close(); }
              catch (SQLException se) { se.printStackTrace(System.err); }
            if ( connection != null ) {
              try { connection.close(); }
              catch (Exception e) { e.printStackTrace(System.err); }
    private static final String RETRIEVE_ALL_NAMES
          = "SELECT code_ggm, name FROM patent ";
    }Now when you wish to use the 'combo box' (also called select lists), you insert this code into your jsp:
    <TR>
    <%@ include file="../incl/patent.jsp" %>
    </TR>
    depending on how your files on your server are organized, the "../incl/patent.jsp"
    tells the container to look up one directory from where the main jsp is to find the 'patent.jsp' file in the 'incl' directory.
    I need some help creating multi-level select lists with JavaScript:
    Can anyone explain this code:
    <%@ page import="java.util.*,kms.domain.*" %>
    <jsp:useBean id="campuses" scope="application" class="java.util.Map" />
    <TR><TD ALIGN='right'>Campus: </TD>
    <TD>
    <select name="campus" size="1" onChange="redirect(this.options.selectedIndex)">
    <option value="0" selected>No Campus</option>
    <% LocationService ls = new LocationService();
       Iterator c = campuses.keySet().iterator();
       Map[] bm = new Map[campuses.size()];
       Map[][] fm = new Map[campuses.size()][0];
       Map[][][] lm = new Map[campuses.size()][0][0];
       int i2 = 0;
       int j2 = 0;
       int k2 = 0;
       int jj = 0;
       int kk = 0;
       while (c.hasNext()) {
          Integer i = (Integer)c.next();
          out.print("<OPTION ");
          out.print("VALUE='" + i.intValue()+ "'>");
          out.print( (String) campuses.get(i) );
          out.print("</OPTION>");
          bm[i2] =  ls.getBuildingsByCampus(i.intValue());
          fm[i2] = new Map[bm[i2].size()];
          lm[i2] = new Map[bm[i2].size()][];
          Iterator b = bm[i2].keySet().iterator();
          j2 = 0;
          while (b.hasNext()) {
            Integer j = (Integer)b.next();
            fm[i2][j2] = ls.getFloorsByBuilding(j.intValue());
            lm[i2][j2] = new Map[fm[i2][j2].size()];
            Iterator f = fm[i2][j2].keySet().iterator();
            k2 = 0;
            while (f.hasNext()) {
              Integer k = (Integer)f.next();
              lm[i2][j2][k2] = ls.getLocationsByFloor(k.intValue());
              k2++;
              kk++;
            j2++;
            jj++;
          i2++;
       } %>
    </select></TD>
    </TR>
    <TR><TD ALIGN='right'>Building: </TD>
    <TD>
    <select name="building" size="1" onChange="redirect1(this.options.selectedIndex)">
    <option value="0" selected>No Building</option>
    </select></TD>
    </TR>
    <TR><TD ALIGN='right'>Floor: </TD>
    <TD>
    <select name="floor" size="1" onChange="redirect2(this.options.selectedIndex)">
    <option value="0" selected>No Floor</option>
    </select></TD>
    </TR>
    <TR><TD ALIGN='right'>Room: </TD>
    <TD>
    <select name="location_id" size="1">
    <option value="0" selected>No Room</option>
    </select></TD>
    </TR>
    <script>
    var cNum = <%=i2%>
    var bNum = <%=jj%>
    var fNum = <%=kk%>
    var cc = 0
    var bb = 0
    var ff = 0
    var temp=document.isc.building
    function redirect(x){
    cc = x
    for (m=temp.options.length-1;m>0;m--)
      temp.options[m]=null
      temp.options[0]=new Option("No Building", "0")
      if (cc!=0) {
        for (i=1;i<=group[cc-1].length;i++){
          temp.options=new Option(group[cc-1][i-1].text,group[cc-1][i-1].value)
    temp.options[0].selected=true
    redirect1(0)
    var group=new Array(cNum)
    for (i=0; i<cNum; i++) {
    group[i]=new Array()
    <% for (int i=0; i< bm.length; i++) {
    Iterator bldgs = bm[i].keySet().iterator();
    int j = 0;
    while (bldgs.hasNext()) {
    Integer intJ =(Integer) bldgs.next(); %>
    group[<%=i%>][<%=j%>] = new Option("<%=bm[i].get(intJ)%>", "<%=intJ%>");
    <% j++;
    } %>
    var group2=new Array(cNum)
    for (i=0; i<cNum; i++) {
    group2[i] = new Array()
    for (j=0; j<=bNum; j++) {
    group2[i][j] = new Array()
    <% for (int i=0; i< fm.length; i++) {
    for (int j=0; j< fm[i].length; j++) {
    Iterator flrs = fm[i][j].keySet().iterator();
    int k = 0;
    while (flrs.hasNext()) {
    Integer intK =(Integer) flrs.next(); %>
    group2[<%=i%>][<%=j%>][<%=k%>] = new Option("<%=fm[i][j].get(intK)%>", "<%=intK%>");
    <% k++;
    } %>
    var temp1=document.isc.floor
    var camp=document.isc.campus.options.selectedIndex
    function redirect1(x){
    bb = x
    for (m=temp1.options.length-1;m>0;m--)
    temp1.options[m]=null
    temp1.options[0]=new Option("No Floor", "0")
    if (cc!=0 && bb!=0) {
    for (i=1;i<=group2[cc-1][bb-1].length;i++){
    temp1.options[i]=new Option(group2[cc-1][bb-1][i-1].text,group2[cc-1][bb-1][i-1].value)
    temp1.options[0].selected=true
    redirect2(0)
    var group3=new Array(cNum)
    for (i=0; i<cNum; i++) {
    group3[i] = new Array()
    for (j=0; j<=bNum; j++) {
    group3[i][j] = new Array()
    for (k=0; k<=fNum; k++) {
    group3[i][j][k] = new Array()
    <% for (int i=0; i< lm.length; i++) {
    for (int j=0; j< lm[i].length; j++) {
    for (int k=0; k< lm[i][j].length; k++) {
    Iterator locs = lm[i][j][k].keySet().iterator();
    int m = 0;
    while (locs.hasNext()) {
    Integer intM =(Integer) locs.next(); %>
    group3[<%=i%>][<%=j%>][<%=k%>][<%=m%>] = new Option("<%=lm[i][j][k].get(intM)%>", "<%=intM%>");
    <% m++;
    } %>
    var temp2=document.isc.location_id
    function redirect2(x){
    ff = x
    for (m=temp2.options.length-1;m>0;m--)
    temp2.options[m]=null
    temp2.options[0]=new Option("No Room", "0")
    if (cc!=0 && bb!=0 && ff!=0) {
    for (i=1;i<=group3[cc-1][bb-1][ff-1].length;i++){
    temp2.options[i]=new Option(group3[cc-1][bb-1][ff-1][i-1].text,group3[cc-1][bb-1][ff-1][i-1].value)
    temp2.options[0].selected=true
    </script>
    This produces a related select list with 4 related lists by outputting JavaScript to the page being served. It works the same way as the first example that I describe but I don't understand the looping...maybe someone could explain how to go from the single select list to a double and/or triple level drill down?

  • JSP problem - drop down combo boxes

    Hi,
    I want to load a database table value into my HTML form's dropdown combo box.
    Actually I want to do this. I need to change employee information. To do this there is a form to enter empNo. Then it will display a .jsp page with the relevant fields of that employee. In this .jsp page, it has a drop down combo box for title. In my db the required title of that employee is Miss.
    But how could I display this value in this dropdown combo box. Then the user can change it as she wish.
    I try it like this way, but it isn't work.
    <select size="1" name="title" style="border: 1px solid #0000FF">
           <jsp:getProperty name="candidate" property="title" />
    </select>     Can anybody tell me hoe to solve this?
    Thanks.

    Hi,
    Thanks for your help.
    I have change that code, as follows.
    <select size="1" name="title" style="border: 1px solid #0000FF">
    <option value="" ><jsp:getProperty name="candidate" property="title" /></option>
    </select> Now it displays the correct title. But how can I display the other 2 options below this? that is Mr. and Mrs. Because the user must have the facility to select Miss. or Mrs. if there any changes she wish to apply.
    Note:
    If a user has a title - Mr. , then the other 2 titles (Miss,Mrs) should be display below it.
    How to solve this?
    Thanks

  • Jsp combo box

    Hi,
    I am new to jsps and i would like to know how to check the property value in jsp.
    I would like to create a combo box and based on what they select i would like to show either textfield or combo box. I mean hiding one and showing another one.
    my code looks some thing like this
    <html:select property="search" >
    <html : option value="itemname"></html:option>
    <html : option value="itemnumber"></html:option>
    So if i select "item name" i would like to display one more combo box or if i select "item number" then i would like to display textfield.
    So could some one please suggest me how to check the value and create these fields.
    Appreciate your help,
    Thanks

    You have three options.
    You may submit the form back to the server after the user selects the item name option. The server then generates and sends back to the user a page with the next combo box. Alternatively, if the user selects the item number option, send a new page with the text field.
    You may use JavaScript and DHTML to literally redraw the page depending on the user's choice. This is not Java related and kinda hard to get working just right, so I won't describe how to do it here. If you decide you absolutely must do this option, there are several JavaScript web sites that will gladly give you some sample code in exchange for some credit.
    Lastly, you can redesign your entire form such that you don't need to hide "the other option." I think you'll find that most web sites do it this way. For example, there will be two clearly separated and marked tables, each with their own submit buttons, and one table will say "Find an Item by Name" and the other will say "Find an Item by Number."
    I personally like the last option best because I can see at a glance what all of my options are, as opposed to having to click buttons to see what I can do, and then the back button if that's not what I want. I will admit that your suggestion would look cool, though.
    Sorry, I wish I could be of more positive help.

  • How to reduce the weight of a combo box in a jsp

    hi friends,
    i have developed a jsp form in which i have placed some combo box and i am using ajax concept for loading the details for a field just above the combo box.
    my problem is that when the ajax loads the records in the form it comes above the combo box .there,the combo box is coming above the ajax listings and hides the records displayed by ajax.can anybody help me to solve this problem of combo box.

    <td class="label">Cash bank general</td><td>   
    <html:select property="accledgeractionform.ledgercbg" styleId="cmbcbg" styleClass="inputbox" style=" width : 130px" tabindex="14" onfocus="setStatusMessage('Select cash bank general')" >
    <html:option value="" styleId="cmbCashBankGeneral">
    </html:option>
    <html:option value="C">Cash</html:option>
    <html:option value="B">Bank</html:option>
    <html:option value="G">General</html:option>
    like this i have created the combo box.
    but it is displayed above the results displayed by the ajax.
    i thought that since combo box is a heavy weight component its weight must be reduced.help me about that

  • Trying to trigger a servlet from .jsp page on combo box change

    I have a jsp page with two combo boxes ( single select ).
    Here's a snippet from the jsp page containing the code for the two combo boxes:
    <form name="frmCountry" id="frmCountry" method="POST">
         <select name="selCountry" id="selCountry">
              <jsp:include page="/country" />
         </select>
    </form>
    <form name="frmCity" id="frmCity" method="POST">
         <select name="selCity" id="selCity">
              <jsp:include page="/city" />
         </select>
    </form>
    "country" and "city" are both mapped to servlets in the web.xml file
    The country servlet successfully connects to the database and retrieves all countries
    and populates the country combo box.
    However, the populating of the city combo box depends on what country
    is selected in the country combo box;
    Here is a snippet of my code from the City servlet:
    ResultSet rs;
    rs = statement.executeQuery("SELECT City.countryID, City.id, City.name " +
                   "FROM City " +
                   "WHERE City.countryID = ( Country id ) " +
                   "ORDER BY City.name");
    Where ( Country id ) has to be somehow retrieved from the Country combo box
    on the jsp page. Country id is actually the "value" property of each <option> in the
    Country combo box. i.e.:
    <option value="5">Portugal</option>
    If it's not possible to retrieve the value property from the option,
    I could always just use the Country name
    So to reiterate, I need the City servlet to be called into action
    any time a different country is selected in the country combo box.
    I'm a newbie to jsp & servlets, so any suggestions much appreciated.
    Edited by: Irish_Fred on Jan 20, 2010 4:29 AM

    Cheers, I came up with a solution using Ajax, where I didn't have to change
    anything in my servlets and only had to make minor changes to my jsp page.
    I didn't want to use any javascript in my web app, but I guess Ajax
    has addressed the issue of cross platform independence.

  • A text box should appear based on combo box selection in a jsp page.

    Hi,
    I have this problem. I ahve an option in the combo box"other". If other is selected then a text box shud appear . Can any one post a quick answer for me. may be a sample of how to do it will help me a lot.
    Thank You,
    Sagar.

    Hi Guys,
    Thnx all for ur replies. Let me explain u the scenario which i work in now. I have a combo box with 4 values "other " being the last of them. If i select "other" then a text box shud appear with the label. what happenes now is i have added onChange whn an option is changed . I have named that functiion refresh for which the code goes like this..
    function refresh()
    window.location.reload(true);
    whn i select an other option thn the whole page gets refreshed and the first value only appears. If i select other then the page refreshes and gets back again to the first value. These guys here use tags like <c: if> <C;choose> <c: otherwise> which am not familiar with. Do pls help me in retaining the option selected.. Thank You.

  • Combo Box question on JSP

    I have two combo boxes. Box 2 is populated dependant on the value of box 1.
    The data wil be coming out of a JavaBean with a connection to a database.
    What would be the best way to acheive this?
    TIA
    Owen Thomas

    Hello Russ9754!
    Might be abit late, but I just read this thread.
    Anyway...I think I have what you are looking for.
    This code creates a dropdown box with the alternatives of your choice. If none of the options is good enough for the user, he/she can choose "other" and enter a more suitable choice in a pop-up javascriptprompt.
    <FORM NAME="formName">
    <SELECT NAME="country" onChange="countryOnChange();">
    <OPTION VALUE="Albania" selected>- = Albania = -</OPTION>
    <OPTION VALUE="Finland">- = Finland = -</OPTION>
    <OPTION VALUE="USA">- = USA = -</OPTION>
    <OPTION VALUE="Other"> Other... </
    OPTION>
    </SELECT>
    </FORM>
    <SCRIPT>
    function countryOnChange(){
    sel = document.formName.country.selectedIndex;
    val = document.formName.country.options[sel].
    value;
    len = document.formName.country.length;
    if (val == "Other"){
    var newcountry = prompt("Enter your country.", "");
    if (newcountry == null) { return; }
    document.formName.country.options[sel].text = newcountry;
    document.formName.country.options[sel].value = newcountry;
    document.formName.country.length = len +1;
    document.formName.country.options[len].text = "Other...";
    document.formName.country.options[len].value = "Other";
    </SCRIPT>

  • Display data in list and combo box

    hi all....
    how to display data from database in list and combo box? i use MYSQL...
    help me please..... tq...

    1 - Write a query to retrieve the data you want from database
    2 - In a servlet, connect to database, Run the query, scroll through the result set and put the data into a list of Java Objects.
    3 - Set a request/session attribute of that list of objects
    4 - Forward to JSP
    5 - In JSP, create a <select> box, and then use a <c:forEach> loop to generate <option> tags from the list.

Maybe you are looking for