aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Related to drop down selecting multiple values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Related to drop down selecting multiple values" Watch "Related to drop down selecting multiple values" New topic
Author

Related to drop down selecting multiple values

Ashutosh Arya
Ranch Hand

Joined: Oct 07, 2008
Posts: 69
Hi,

I wanted to have a drop down in which multiple values can be selected at a time but at the same time i want to set that how many values can be selected (for eg: user can set whether 3 values can be selected or 5 values can be selected at a time).

Please help,

Aashu.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

you can validate the number of selection on serverside
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

Nothing to do with JSP, so moved to a more appropriate forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mansi Mishra
Ranch Hand

Joined: Dec 26, 2008
Posts: 50
Ashutosh Arya wrote:Hi,

I wanted to have a drop down in which multiple values can be selected at a time but at the same time i want to set that how many values can be selected (for eg: user can set whether 3 values can be selected or 5 values can be selected at a time).

Please help,

Aashu.



Hi Aashu...

This is possible using javascript as well...
iterate through the list, and check each element, if its selected...
set a counter to check the no. of elements selected...

Please find the code below implemented with a <h:selectManyListbox id="teamList">

var teamCount = (document.getElementById('formName:teamList')).length;
var count=0;
for (var i = 0; i < teamCount; i = i + 1) {
var tempChar = (document.getElementById('formName:teamList')).options[i];
if(tempChar.selected){
count=count+1;
}
if(count>1)
break;
}

if(count>1){
alert("Only single team can be selected");
}

The above code allows only one team to be selected.
But in case you have a huge list with thousand of records, this could take some time...


All the Best
Mansi

http://splashpress.blogspot.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Related to drop down selecting multiple values
 
Similar Threads
delete from slecet box
setting the selected option in a select element
Multiple Consoles in Eclipse
Reg : Drop-down box
drop down list doPost() servlet