getting values from drop down menu

Thread Solved

Join Date: Dec 2004
Posts: 8
Reputation: dannyfang is an unknown quantity at this point 
Solved Threads: 0
dannyfang dannyfang is offline Offline
Newbie Poster

getting values from drop down menu

 
0
  #1
Jan 28th, 2005
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
Attached Files
File Type: java AdmProfileLockOut.java (14.1 KB, 133 views)
File Type: doc frmLockOut.doc (13.0 KB, 110 views)
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: getting values from drop down menu

 
0
  #2
Jan 28th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 2
Reputation: javachiru is an unknown quantity at this point 
Solved Threads: 1
javachiru javachiru is offline Offline
Newbie Poster

Re: getting values from drop down menu

 
0
  #3
Apr 18th, 2005
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>
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: getting values from drop down menu

 
0
  #4
Apr 19th, 2005
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 2
Reputation: javachiru is an unknown quantity at this point 
Solved Threads: 1
javachiru javachiru is offline Offline
Newbie Poster

Re: getting values from drop down menu

 
0
  #5
Apr 20th, 2005
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...
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 2
Reputation: tirupati_dand is an unknown quantity at this point 
Solved Threads: 1
tirupati_dand tirupati_dand is offline Offline
Newbie Poster

Re: getting values from drop down menu

 
0
  #6
Sep 27th, 2005
how to get parent child dropdown(country,state,city)dynamically
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 216
Reputation: hooknc is an unknown quantity at this point 
Solved Threads: 8
hooknc hooknc is offline Offline
Posting Whiz in Training

Re: getting values from drop down menu

 
0
  #7
Oct 3rd, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 7
Reputation: yup is an unknown quantity at this point 
Solved Threads: 1
yup yup is offline Offline
Newbie Poster

Re: getting values from drop down menu

 
0
  #8
Jan 22nd, 2006
Hi,
Try this, it works for me
  1. <% String days= request.getParameterValues("Day"); %>
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: getting values from drop down menu

 
0
  #9
Jan 22nd, 2006
except that it should be a String array of course
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 1
Reputation: kianfatt1982 is an unknown quantity at this point 
Solved Threads: 1
kianfatt1982 kianfatt1982 is offline Offline
Newbie Poster

Re: getting values from drop down menu

 
0
  #10
Feb 9th, 2006
lets say I have a select box like
  1. <SELECT id="MySelect" multiple >
  2. <option value="A">Text 1<option>
  3. <option value="B">Text 2<option>
  4. <option value="C">Text 3<option>
  5. </SELECT>

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

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

  1. document.getElementById("MySelect").value;
  2. 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 ?
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 69243 | Replies: 12
Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC