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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark ""Select Boxes" - Same Name" Watch ""Select Boxes" - Same Name" New topic
Author

"Select Boxes" - Same Name

Sam Ferns
Greenhorn

Joined: Sep 18, 2005
Posts: 10
Hi Guys !

Having issues with select boxes with same names. Generally, if other HTML components are of the same name on the same page then, they are processed as an "array". Thus, two "firstname" text boxes would be processed as an array of "firstname" having size=2. However, when the select box is used with same names then, as usual an array is created but, this time the array contains the selected elements in both the select boxes(all in the same array). How should selected elements from the first list box be retreived, now that all the selected elements of the first list box and second list box are all contained in the "single array". How should i go about ? Please suggest.

Thank You.

Cheers,
Sam
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

When you name the elements with the same name, they are logically considered a single element from the point of view of the server. Thus, the array of values that you receive from request.getParameterValues() will be the union of the selections from the elements. There is no way to determine which selections came from which element.

If that's not the behavior you want, name the select elements differently.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sam Ferns
Greenhorn

Joined: Sep 18, 2005
Posts: 10
Hi !

Thanks for your inputs. Please confirm if i get you right. What you are saying is that it is not possible to extract an array(representing an "individual" list box selected items) from an array(which represents all the list boxes with same names on the page). Basically, what i have here are multiple dynamically generated rows wherein each row represents a user details along with a select box indicating the users assigned roles. These roles are to be edited for multiple users at a time and submitted to the server for processing. Kindly, please let me know if such type of functionality is possible.

Thanks a lot.

Cheers,
Sam
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
If they are dynamically generated, couldn't you give them dynamic names?

Eric
Sam Ferns
Greenhorn

Joined: Sep 18, 2005
Posts: 10
Hi !

Thanks for your reply. As mentioned, can give dynamic names to the select boxes as "listbox_name[0]", "listbox_name[1]" and so on. But, how should this component be defined in struts action form class. I tried dynamically assigning names as described above but, when the items are selected from say "listbox_name[0]" then even though multiple items may be selected from this particular list box, the server shows on the 1st. selected items from this list box(not all the selected items).

Kindly please suggest !

Cheers,
Savio
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "Select Boxes" - Same Name