File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes index of option Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Reply locked New topic
Author

index of option

Sudhir Pawar
Greenhorn

Joined: Sep 27, 2012
Posts: 25
please tell me jsp code to get index value of option list(drop down list)

i have created drop down list as follows
<select id="instance2" >
<option value="name">Item0</option>
<option value="name">Item1</option>
<option value="name">Item2</option>
</select>


now i want to get index value of selected item in variable then how can i do this??
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Are you submitting the form where this select is to a servlet or to another JSP file ?


[My Blog]
All roads lead to JavaRanch
Sudhir Pawar
Greenhorn

Joined: Sep 27, 2012
Posts: 25
submitting form to current jsp file.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

You can access the value using the Expression Language (EL) : ${instance2}.
But you'll get the value, not the label. In your example, all options have the same value. You should give them different values.
Sudhir Pawar
Greenhorn

Joined: Sep 27, 2012
Posts: 25
but how to store index value in variable?
give me proper eg. with stntax.
Because i tried but shows ; expected error.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

But how to store index value in variable?

Which index ?

give me proper eg. with stntax.

It would be better if you could come up with a solution by yourself.

Because i tried but shows ; expected error.

Where ? Maybe you should post your JSP code here.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61309
    
  66

Please do not post the same question more than once. I am closing this one so that any discussion can occur in the duplicate post.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
GeeCON Prague 2014
 
subject: index of option