Results 1 to 6 of 6
  1. #1
    hussainzim is offline Member
    Join Date
    May 2008
    Posts
    14
    Rep Power
    0

    Default Add data to combobox in page load

    i want to add data to a combo box dynamically in a page load in jsp.currently i hav got da data from a servlet to the jsp.thank u in advance...

  2. #2
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    12

    Default

    HTML are not that Dynamic so you must be Creative to make it look Dynamic. YOu can use Javascript or Ajax to do it. But i dont know that yet. So here is my solution using only JSP and Servlet.

    In your Servlet you should have this code
    wherein OptionFromServlet is a String that you will be passing from Servlet to the JSP
    Java Code:
    <select Type="ComboBox" name="drop">
                                <%=OptionFromServlet>
    </select>
    In your Servlet you have this
    Java Code:
    String Temp[] = {"One","Two","Three"}; //here is where your list is
    String OptionToJSP=null;
    Int ctr = Temp.length(); 
    for(int i=0; i<ctr; i++){
          OptionToJSP += "<OPTION>" + Temp[i] + "</OPTION>";
    } OptionToJSP = OptionToJSP.substring(4);
    
    //Then Return OptionToJSP to the JSP. . .
    The only problem with this is when the page is loaded the combox is null. You have to put a refresh, to Load the data from the Servlet to the JSP. =P

    I Hope that Helps
    Mind only knows what lies near the heart, it alone sees the depth of the soul.

  3. #3
    hussainzim is offline Member
    Join Date
    May 2008
    Posts
    14
    Rep Power
    0

    Default

    i want to load data into the combo box without clicking any button.daata should be there when the page is loaded.hw can i do that??

  4. #4
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    12

    Default

    Im still a noob in J2EE, lets wait for the experts to answer your question. =)
    Mind only knows what lies near the heart, it alone sees the depth of the soul.

  5. #5
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    12

    Default

    in your jSP
    Java Code:
    <script>
       window.onLoad = init();
       function init(){
          fill_my_combo_box( myComboBoxID, listOrMapOfValuesToPopulate);
       }
    </script>
    is that ookay, or should i write the code for fill_my_combo_box as well :D
    i am the future

  6. #6
    hussainzim is offline Member
    Join Date
    May 2008
    Posts
    14
    Rep Power
    0

    Default

    hey..im kinda new to jsp and stuff so can u write the code for fill_my_combo_box as well..plss :)

Similar Threads

  1. [SOLVED] Adding ComboBox
    By impact in forum New To Java
    Replies: 2
    Last Post: 05-02-2008, 08:43 PM
  2. How to display Tabuler Data in J2EE application on jsp page
    By AMATYA-CHANAKYA in forum Advanced Java
    Replies: 2
    Last Post: 04-23-2008, 05:54 PM
  3. HashMap and ComboBox
    By banie in forum AWT / Swing
    Replies: 2
    Last Post: 03-25-2008, 11:58 PM
  4. how to load a servlet on index.jsp page...
    By sujithc34 in forum Java Servlet
    Replies: 1
    Last Post: 01-19-2008, 12:28 AM
  5. ComboBox with database options
    By Goldy in forum Advanced Java
    Replies: 0
    Last Post: 12-01-2007, 09:43 PM

Posting Permissions

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