Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi-Select Combo Box And Javascript

Status
Not open for further replies.

Deltaflyer

Programmer
Oct 11, 2000
184
GB
I have this combo box,

<select width=450 name=selcust size=5 multiple onclick=javascript()>
<option value = 1>1</option>
<option value = 2>2</option>
<option value = 3>3</option>
<option value = 4>4</option>
<option value = 5>5</option>
<option value = 6>6</option>
<option value = 7>7</option>
<option value = 8>8</option>
</select>


how can i limit the maximum allowed selections. i.e. select 4 off of the list and no more.

Thanks for any help DeltaFlyer ;-)

DeltaFlyer - The Only Programmer To Crash With Style.
 
Well, just finished one that makes you unselect another before you can select a new one. You need to create a new array for each selectbox you want to use it on. (thanx for the challenge:):

<html>
<head>
<title>For Delta</title>

<script>
//altered to return
Array.prototype.contains=function(zy)
{var xi = this.length;for(var i=0;i<xi;i++)
{if(this==zy){return i}}return false}
Array.prototype.remove=function(dx){
for(var i=0,n=0;i<this.length;i++){
if(this!=this[dx]){this[n++]=this}}
this.length-=1}


function restrictAmount(o,amt,arr)
{
var i,oops,oopslen,scnt,arlen,tst;
scnt = 0
oops = o.options;
oopslen = oops.length
for(i=0;i<oopslen;i++)
{
tst=arr.contains(i)
if(tst||new String(tst)=='0')
{
if(oops.selected){scnt++;continue}
else{arr.remove(tst);continue}
}
if(oops.selected)
{
if(++scnt<=amt){arr[arr.length]=i;}
}
oops.selected=false
}
arlen = arr.length
for(i=0;i<arlen;i++)
{
oops[arr].selected=true
}
}
Global_selected_array = new Array()

</script>

</head>

<body>

<select multiple onChange=&quot;restrictAmount(this,3,Global_selected_array)&quot;>
<option value=1>1
<option value=1>2
<option value=1>3
<option value=1>4
<option value=1>5
<option value=1>6
<option value=1>7
</select>

</body>
</html>
jaredn@subdimension.com -
 
Nice one jared, absolutely fantastic!!

Does just what i wanna do!!!! DeltaFlyer ;-)

DeltaFlyer - The Only Programmer To Crash With Style.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top