954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

getting values from drop down menu

HI,

I wish to get the values from the drop down menu selected by a user from the HTML page and pass this value into my servlet program for processing.

In my servlet program, I've used the getParameter() function to obtain the value from the drop down menu selected.

- Select -SundayMondayTuesdayWednesdayThursdayFridaySaturday


String days= request.getParameter("Day");
System.out.println("DAY =" +days);

However, the value of the parameter "day" seems empty. May I know what is the correct method of getting the value selected from the drop down menu into my servlet? It did work when I use Javascript functions to extract it though (function getDay() in frmLockOut.html).

Attached are my JSP(frmLockOut.html) and Servlet(AdmProfileLockOut.java- see function add( ) ) source code files for reference.

Thanks
Danny

Attachments AdmProfileLockOut.java (14.15KB) frmLockOut.doc (12.99KB)
dannyfang
Newbie Poster
8 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

Don't attach things, I won't open them.

Most likely you didn't place the select inside an html form which would cause the value to not be passed in the request.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Hi , all
Can anyone please tell me how to get multiple values from a drop down menu . I know that we have to specify MULTIPLE in SELECT tag
This is my simple code, I wnat to display selected values in dd.jsp , if anyone can help me ,, PLEASE DO IT SOOON..


Authoring
Internet
Location
Multimedia
Reference
Software

javachiru
Newbie Poster
2 posts since Apr 2005
Reputation Points: 10
Solved Threads: 1
 

PLEASE DO IT SOOON
Wrong way to ask a question. We're not here to do your bidding at your whim. Maybe you should have started researching sooner if you're in a hurry now.

the multiselect is not possible with a dropdown, only with a selectbox.

You can get the values with getParameterValues(String) on the ServletRequest.
The API docs will give you more information.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

hey , thanks very much for your reply..!!! I had already solved it but you were absolutely correct about getParameterValues() ..I appreciate your knowledge.
Thanks Again...

javachiru
Newbie Poster
2 posts since Apr 2005
Reputation Points: 10
Solved Threads: 1
 

how to get parent child dropdown(country,state,city)dynamically

tirupati_dand
Newbie Poster
2 posts since Sep 2005
Reputation Points: 10
Solved Threads: 1
 

You should be creating a new topic for a new question. You also might want to be asking this question in the JavaScript forum.

Regards,

Nate

hooknc
Posting Whiz in Training
219 posts since Aug 2005
Reputation Points: 11
Solved Threads: 8
 

Hi,
Try this, it works for me :D

<% String days= request.getParameterValues("Day"); %>
yup
Newbie Poster
7 posts since Jan 2006
Reputation Points: 10
Solved Threads: 1
 

except that it should be a String array of course ;)

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

lets say I have a select box like

<SELECT id="MySelect" multiple >
  <option value="A">Text 1<option>
  <option value="B">Text 2<option>
  <option value="C">Text 3<option>
</SELECT>


ok now if I want to get all the selected values of this multiple select box I just call :-

String[] arrValues[] = objRequest.getParameterValues("MySelect");


but now my problem is how do I get the text values.

I know in JavaScript I can get both the text and the values by just issuing :-

document.getElementById("MySelect").value;
document.getElementById("MySelect").text;


but how do I do this in Servlet, how do I do this in J2EE programmming ? :!:How do I get the selected text value ?

kianfatt1982
Newbie Poster
1 post since Feb 2006
Reputation Points: 10
Solved Threads: 1
 

Hi, Try this, it works for me :D

<% String days= request.getParameterValues("Day"); %>

Mine doesn't work, whats wrong?

NairobiCentralCoastEasternNorth EasternNyanzaRift ValleyWestern
<%
<% String[] province = request.getParameterValues("mySelection");%>

mutuah
Newbie Poster
1 post since Aug 2007
Reputation Points: 10
Solved Threads: 1
 

you have not written multiple in ...see previous posts for better understanding...your code should have been smthing like this

litu
Newbie Poster
3 posts since Apr 2009
Reputation Points: 10
Solved Threads: 1
 

Nice attempt, but post is 2 years old...

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

HI,

I wish to get the values from the drop down menu selected by a user from the HTML page and pass this value into my servlet program for processing.

In my servlet program, I've used the getParameter() function to obtain the value from the drop down menu selected.

- Select -SundayMondayTuesdayWednesdayThursdayFridaySaturday

String days= request.getParameter("Day"); System.out.println("DAY =" +days);

However, the value of the parameter "day" seems empty. May I know what is the correct method of getting the value selected from the drop down menu into my servlet? It did work when I use Javascript functions to extract it though (function getDay() in frmLockOut.html).

Attached are my JSP(frmLockOut.html) and Servlet(AdmProfileLockOut.java- see function add( ) ) source code files for reference.

Thanks Danny

Please give name value of select tag in double quotes

smithatm89
Newbie Poster
1 post since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

HI,

I wish to get the values from the drop down menu selected by a user from the HTML page and pass this value into my servlet program for processing.

In my servlet program, I've used the getParameter() function to obtain the value from the drop down menu selected.

- Select -SundayMondayTuesdayWednesdayThursdayFridaySaturday

String days= request.getParameter("Day"); System.out.println("DAY =" +days);

However, the value of the parameter "day" seems empty. May I know what is the correct method of getting the value selected from the drop down menu into my servlet? It did work when I use Javascript functions to extract it though (function getDay() in frmLockOut.html).

Attached are my JSP(frmLockOut.html) and Servlet(AdmProfileLockOut.java- see function add( ) ) source code files for reference.

Thanks Danny


try this one:
1) capture the value of the dropdown select box with javascript using the getElementById command.
2) then next step to do is simply pass the value captured to the servlet. thats all! its gonna work! I guarantee you!

batousai
Newbie Poster
1 post since Mar 2010
Reputation Points: 10
Solved Threads: 0
 
try this one: 1) capture the value of the dropdown select box with javascript using the getElementById command. 2) then next step to do is simply pass the value captured to the servlet. thats all! its gonna work! I guarantee you!

First of all this thread is 5 years old.
Second what you said is not necessary for the solution. The html code is correct and all is needed is to submit the form. You don't need javascript in order to put the value to another field and send that.

If you have read the entire you would know what was the problem.


And it is time to close this thread, before another tries to post their own crazy idea.

javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

Thread close

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You