User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 363,558 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,885 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 38884 | Replies: 10
Reply
Join Date: Dec 2004
Posts: 8
Reputation: dannyfang is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dannyfang dannyfang is offline Offline
Newbie Poster

getting values from drop down menu

  #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, 88 views)
File Type: doc frmLockOut.doc (13.0 KB, 67 views)
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,583
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 186
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: getting values from drop down menu

  #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  
Join Date: Apr 2005
Posts: 2
Reputation: javachiru is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
javachiru javachiru is offline Offline
Newbie Poster

Re: getting values from drop down menu

  #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  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,583
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 186
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: getting values from drop down menu

  #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.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Join Date: Apr 2005
Posts: 2
Reputation: javachiru is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
javachiru javachiru is offline Offline
Newbie Poster

Re: getting values from drop down menu

  #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  
Join Date: Sep 2005
Posts: 2
Reputation: tirupati_dand is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tirupati_dand tirupati_dand is offline Offline
Newbie Poster

Re: getting values from drop down menu

  #6  
Sep 27th, 2005
how to get parent child dropdown(country,state,city)dynamically
Reply With Quote  
Join Date: Aug 2005
Location: Socialist Republic of Boulder
Posts: 216
Reputation: hooknc is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
hooknc hooknc is offline Offline
Posting Whiz in Training

Re: getting values from drop down menu

  #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  
Join Date: Jan 2006
Posts: 7
Reputation: yup is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
yup yup is offline Offline
Newbie Poster

Re: getting values from drop down menu

  #8  
Jan 21st, 2006
Hi,
Try this, it works for me
<% String days= request.getParameterValues("Day"); %> 
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,583
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 186
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: getting values from drop down menu

  #9  
Jan 22nd, 2006
except that it should be a String array of course
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Join Date: Feb 2006
Posts: 1
Reputation: kianfatt1982 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kianfatt1982 kianfatt1982 is offline Offline
Newbie Poster

Question Re: getting values from drop down menu

  #10  
Feb 9th, 2006
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 ?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JSP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 5:26 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC