943,970 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Marked Solved
  • Views: 142892
  • JSP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jan 28th, 2005
-1

getting values from drop down menu

Expand Post »
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, 1302 views)
File Type: doc frmLockOut.doc (13.0 KB, 1382 views)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dannyfang is offline Offline
8 posts
since Dec 2004
Jan 28th, 2005
0

Re: getting values from drop down menu

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Apr 18th, 2005
-1

Re: getting values from drop down menu

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>
Reputation Points: 10
Solved Threads: 1
Newbie Poster
javachiru is offline Offline
2 posts
since Apr 2005
Apr 19th, 2005
0

Re: getting values from drop down menu

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Apr 20th, 2005
0

Re: getting values from drop down menu

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...
Reputation Points: 10
Solved Threads: 1
Newbie Poster
javachiru is offline Offline
2 posts
since Apr 2005
Sep 27th, 2005
0

Re: getting values from drop down menu

how to get parent child dropdown(country,state,city)dynamically
Reputation Points: 10
Solved Threads: 1
Newbie Poster
tirupati_dand is offline Offline
2 posts
since Sep 2005
Oct 3rd, 2005
0

Re: getting values from drop down menu

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
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
hooknc is offline Offline
216 posts
since Aug 2005
Jan 22nd, 2006
0

Re: getting values from drop down menu

Hi,
Try this, it works for me
JSP Syntax (Toggle Plain Text)
  1. <% String days= request.getParameterValues("Day"); %>
yup
Reputation Points: 10
Solved Threads: 1
Newbie Poster
yup is offline Offline
7 posts
since Jan 2006
Jan 22nd, 2006
0

Re: getting values from drop down menu

except that it should be a String array of course
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Feb 9th, 2006
0

Re: getting values from drop down menu

lets say I have a select box like
JSP Syntax (Toggle Plain Text)
  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 :-

JSP Syntax (Toggle Plain Text)
  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 :-

JSP Syntax (Toggle Plain Text)
  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 ?
Reputation Points: 10
Solved Threads: 1
Newbie Poster
kianfatt1982 is offline Offline
1 posts
since Feb 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in JSP Forum Timeline: Database connection error
Next Thread in JSP Forum Timeline: Locale wise 301 redirect in jsp





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC