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 name=Day>
<OPTION value="" selected>- Select -</OPTION>
<OPTION value=Sunday>Sunday</OPTION>
<OPTION value=Monday>Monday</OPTION>
<OPTION value=Tuesday>Tuesday</OPTION>
<OPTION value=Wednesday>Wednesday</OPTION>
<OPTION value=Thursday>Thursday</OPTION>
<OPTION value=Friday>Friday</OPTION>
<OPTION value=Saturday>Saturday</OPTION>
</SELECT>


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

Re: getting values from drop down menu 80 80

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.

Re: getting values from drop down menu 80 80

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..

<FORM Action="dd.jsp">
<SELECT NAME="drop" SIZE=3 multiple>
<OPTION> Authoring
<OPTION> Internet
<OPTION> Location
<OPTION> Multimedia
<OPTION> Reference
<OPTION> Software
</SELECT>

<input type ="submit">
</FORM>

Re: getting values from drop down menu 80 80

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.

Re: getting values from drop down menu 80 80

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...

Re: getting values from drop down menu 80 80

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

Re: getting values from drop down menu 80 80

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

Re: getting values from drop down menu 80 80

Hi,
Try this, it works for me :D

<% String days= request.getParameterValues("Day"); %>
Re: getting values from drop down menu 80 80

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

Re: getting values from drop down menu 80 80

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 ?

Re: getting values from drop down menu 80 80

Hi,
Try this, it works for me :D

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

Mine doesn't work, whats wrong?


<select name="mySelection">
<option value ="Nairobi" selected>Nairobi</option>
<option value ="Central">Central</option>
<option value ="Central">Coast</option>
<option value ="Eastern">Eastern</option>
<option value ="North Eastern">North Eastern</option>
<option value ="Nyanza">Nyanza</option>
<option value ="Rift Valley">Rift Valley</option>
<option>Western</option>
</select>
<%
<% String[] province = request.getParameterValues("mySelection");%>

Re: getting values from drop down menu 80 80

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

<select name="abc" multiple>
<!-- whatever option you want to put in-->
</select>

Re: getting values from drop down menu 80 80

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

Re: getting values from drop down menu 80 80

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 name=Day>
<OPTION value="" selected>- Select -</OPTION>
<OPTION value=Sunday>Sunday</OPTION>
<OPTION value=Monday>Monday</OPTION>
<OPTION value=Tuesday>Tuesday</OPTION>
<OPTION value=Wednesday>Wednesday</OPTION>
<OPTION value=Thursday>Thursday</OPTION>
<OPTION value=Friday>Friday</OPTION>
<OPTION value=Saturday>Saturday</OPTION>
</SELECT>


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

Re: getting values from drop down menu 80 80

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 name=Day>
<OPTION value="" selected>- Select -</OPTION>
<OPTION value=Sunday>Sunday</OPTION>
<OPTION value=Monday>Monday</OPTION>
<OPTION value=Tuesday>Tuesday</OPTION>
<OPTION value=Wednesday>Wednesday</OPTION>
<OPTION value=Thursday>Thursday</OPTION>
<OPTION value=Friday>Friday</OPTION>
<OPTION value=Saturday>Saturday</OPTION>
</SELECT>


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!

Re: getting values from drop down menu 80 80

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.

Re: getting values from drop down menu 80 80

Thread close

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.