Thursday, March 29, 2012

list box

I have a list box that is populated from my dataset. I add a new item in
there called "ALL". In this list box the user can select more then one item,
my question is, if they select ALL can i disable the multi selection
capability? So if ALL is selected they can't hold down the CTRL key and
select more.I believe, there is no builtin property in listbox control for this

but, this is simple to implement in javascript.. you will not be able to
disable some options in a select box but will be able to deselect the other
selections or display a message if ALL is selected.

Following function would deselect all except first item in the list...

function Deselect()
{
var theDayElement = window.document.form1.cmbDay

var optionCounter;
for (optionCounter = 1; optionCounter < theDayElement.length;
optionCounter++)
{
theDayElement.options[optionCounter].selected=false;
}
}

This function would check if first option (ALL) is selected and call
deselect() to deselect all other options

function CheckValue()
{
if(window.document.form1.cmbDay.options[0].selected == true)
DeselectAll();
}

your Select tag would look like below

<SELECT NAME="cmbDay" ID="cmbDay" multiple onchange="CheckValue();"
Hope this helps...

"NuB" wrote:

> I have a list box that is populated from my dataset. I add a new item in
> there called "ALL". In this list box the user can select more then one item,
> my question is, if they select ALL can i disable the multi selection
> capability? So if ALL is selected they can't hold down the CTRL key and
> select more.
>
>
>

0 comments:

Post a Comment