Populating dropdown dynamically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • itgaurav198
    New Member
    • Oct 2007
    • 41

    #1

    Populating dropdown dynamically

    Hi,

    I have an arraylist(al) in which I have some values. I want to populate these values in my dropdown list. I have used the following code


    Code:
    <select name="select">
    <%for(int i=0;i<al.size();i++){%>
    <Option value="<%al.get(i);%>"><%=al.get(i)%></Option>
    <%}%>
    </select>

    I gets populaated but when i want to print its value it shows blank.
    Can anybody tell me the reason and some other alternative to populate the dropdown so that i can get the selected value.

    Thanks
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by itgaurav198
    Hi,

    I have an arraylist(al) in which I have some values. I want to populate these values in my dropdown list. I have used the following code


    Code:
    <select name="select">
    <%for(int i=0;i<al.size();i++){%>
    <Option value="<%al.get(i);%>"><%=al.get(i)%></Option>
    <%}%>
    </select>

    I gets populaated but when i want to print its value it shows blank.
    Can anybody tell me the reason and some other alternative to populate the dropdown so that i can get the selected value.

    Thanks
    Your value is not set properly.
    You should have it as [CODE=java]value="<%=al.ge t(i)%>"[/CODE]

    Comment

    • itgaurav198
      New Member
      • Oct 2007
      • 41

      #3
      Originally posted by r035198x
      Your value is not set properly.
      You should have it as [CODE=java]value="<%=al.ge t(i)%>"[/CODE]
      Hi,
      Now i am able to display its value but when I want to get its value on a servlet that is called from this jsp it shows blank.

      Please tell me the reason.

      Thanks

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by itgaurav198
        Hi,
        Now i am able to display its value but when I want to get its value on a servlet that is called from this jsp it shows blank.

        Please tell me the reason.

        Thanks
        How are you retrieving this value from the servlet?
        Can you post the code that'd displaying the blank values?

        Comment

        • itgaurav198
          New Member
          • Oct 2007
          • 41

          #5
          Originally posted by r035198x
          How are you retrieving this value from the servlet?
          Can you post the code that'd displaying the blank values?
          Hi,

          I am using

          Code:
          String str=request.getParameter("name value od dropdown");
          PrintWriter pw=response.getWriter();
          pw.println("<html><body>");
          pw.println(str);
          pw.println("</body></html>");
          Is it ok to get the selected value of dropdown using request.getPara meter()?

          Thanks

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by itgaurav198
            Hi,

            I am using

            Code:
            String str=request.getParameter("name value od dropdown");
            PrintWriter pw=response.getWriter();
            pw.println("<html><body>");
            pw.println(str);
            pw.println("</body></html>");
            Is it ok to get the selected value of dropdown using request.getPara meter()?

            Thanks
            Yes it's OK (correct) to use request.getPara meter for select values.
            What is the name of the select that you are passing to the getParameter method? It has to match exactly (case sensitive) with the name that you used on your form for the select.
            I also suggest that you change the name of your select from "select" to something else that describes the values stored by the select.

            Comment

            • itgaurav198
              New Member
              • Oct 2007
              • 41

              #7
              Originally posted by r035198x
              Yes it's OK (correct) to use request.getPara meter for select values.
              What is the name of the select that you are passing to the getParameter method? It has to match exactly (case sensitive) with the name that you used on your form for the select.
              I also suggest that you change the name of your select from "select" to something else that describes the values stored by the select.
              Hi,
              Thanx for ur response.
              I am using the dropdown name as location.

              Actually first i change one dropdown and call a servlet in which i fetch the values for another dropdown and passes it to the same jsp using request dispatcher.
              But when i submit this jsp to another servlet i am not getting the values of fields.
              Please help.

              Thanks

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by itgaurav198
                Hi,
                Thanx for ur response.
                I am using the dropdown name as location.

                Actually first i change one dropdown and call a servlet in which i fetch the values for another dropdown and passes it to the same jsp using request dispatcher.
                But when i submit this jsp to another servlet i am not getting the values of fields.
                Please help.

                Thanks
                When you pass the values from the servlet to the JSP are they displaying properly on that JSP?

                Comment

                Working...