471,853 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,853 software developers and data experts.

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


Expand|Select|Wrap|Line Numbers
  1. <select name="select">
  2. <%for(int i=0;i<al.size();i++){%>
  3. <Option value="<%al.get(i);%>"><%=al.get(i)%></Option>
  4. <%}%>
  5. </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
Oct 26 '07 #1
7 17728
r035198x
13,262 8TB
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


Expand|Select|Wrap|Line Numbers
  1. <select name="select">
  2. <%for(int i=0;i<al.size();i++){%>
  3. <Option value="<%al.get(i);%>"><%=al.get(i)%></Option>
  4. <%}%>
  5. </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
Expand|Select|Wrap|Line Numbers
  1. value="<%=al.get(i)%>"
Oct 26 '07 #2
Your value is not set properly.
You should have it as
Expand|Select|Wrap|Line Numbers
  1. value="<%=al.get(i)%>"
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
Oct 26 '07 #3
r035198x
13,262 8TB
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?
Oct 26 '07 #4
How are you retrieving this value from the servlet?
Can you post the code that'd displaying the blank values?
Hi,

I am using

Expand|Select|Wrap|Line Numbers
  1. String str=request.getParameter("name value od dropdown");
  2. PrintWriter pw=response.getWriter();
  3. pw.println("<html><body>");
  4. pw.println(str);
  5. pw.println("</body></html>");
Is it ok to get the selected value of dropdown using request.getParameter()?

Thanks
Oct 26 '07 #5
r035198x
13,262 8TB
Hi,

I am using

Expand|Select|Wrap|Line Numbers
  1. String str=request.getParameter("name value od dropdown");
  2. PrintWriter pw=response.getWriter();
  3. pw.println("<html><body>");
  4. pw.println(str);
  5. pw.println("</body></html>");
Is it ok to get the selected value of dropdown using request.getParameter()?

Thanks
Yes it's OK (correct) to use request.getParameter 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.
Oct 26 '07 #6
Yes it's OK (correct) to use request.getParameter 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
Oct 26 '07 #7
r035198x
13,262 8TB
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?
Oct 26 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by dmedina | last post: by
1 post views Thread by Mike P | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.