Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Related to drop down selecting multiple values

 
Ashutosh Arya
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can validate the number of selection on serverside
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing to do with JSP, so moved to a more appropriate forum.
 
Mansi Mishra
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic