> Yogesh Agarwal asks:
> I have a problem and I am stuck with it for quite sometime now. I am
> using JDBC in servlets and I have a drop down menu where the options are
> read from the database. Now I want to read the selectedIndex from the
> drop down menu and use it as a key to retrieve data from the tables. I
> am not able to figure out how do I read the selectedIndex in a servlet.
> Any detailed help is appreciated.
ugur serkan replies:
> Could you please define what you really want to do? I mean indeed if you
> have a form with a submit button on it, when the submit button is
> pressed, all the name-value pairs are sent to the servlet pointed to by
> the action part of the form. So dropdown menus are not different from
> the text fields in the manner their value is sent to the servlet and
> parsed with the request.getParameter() method. If you can be more
> specific, I can send an example...
If you have an HTML form with a <SELECT> list, it works like this:
<SELECT NAME="blah">
<OPTION value="1">red
<OPTION value="2">white
<OPTION value="3">blue
<OPTION value="4">green
</SELECT>
When the user selects "white" and clicks the submit button, the
argument sent to the server is "blah=2". Value doesn't have to be a
number - it can be any text. The value of each option could be the
same as a the name on the select box.
<SELECT NAME="blah">
<OPTION value="red">red
<OPTION value="white">white
<OPTION value="blue">blue
<OPTION value="green">green
</SELECT>
If you want the value of the option to be the same as the name
of the option, you can take the shortcut of not including any value=""
in the <OPTION> tag:
<SELECT NAME="blah">
<OPTION>red
<OPTION>white
<OPTION>blue
<OPTION>green
</SELECT>
Personally, I favor specifying the value. I like being explicit in my
programming languages; implicit behaviors usually get me in trouble :-).
I strongly suggest anybody doing HTML-heavy servlets should pick
up O'Reilly's _HTML: The Definitive Guide_.
Steven J. Owens
[EMAIL PROTECTED]
[EMAIL PROTECTED]
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html