Here's a start on the action script...

<cfsavecontent variable="checkit_as">
var myObjArray = mylist.selectedItems; if (myObjArray.length > 3)
{alert("You may only choose 3 items form the list!");}
</cfsavecontent>

<cfform format="flash">
<cfselect name="mylist" query="tmp" display="thedisplay" value="thevalue"
multiple="yes" size="4" onchange="#checkit_as#" />
</cfform>

That will alert you anytime you make a selectionand the total number of
selected items are greater than 3. Still needs a method to deselect the item
when the alert is triggered.

 
..:.:.:.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com

-----Original Message-----
From: Bobby Hartsfield [mailto:[EMAIL PROTECTED] 
Sent: Sunday, December 04, 2005 6:07 PM
To: CF-Talk
Subject: RE: Constraining cfselect

Well, in a normal cfselect... you'd have to roll your own js for it...
something like this should work fine...


<script type="text/javascript">
var selConstraint = 3;

function doit(obj)
{
        var selCount = 0;
        for (i=0; i < obj.options.length; i++)
        {
                if ( obj.options[i].selected )
                {
                        if (selCount < selConstraint)
                        {
                                selCount = selCount + 1;
                        }
                        else
                        {
                                obj.options[i].selected = false;
                                alert("You may only choose " + selConstraint
+ " items form the list.");
                        }
                }
        }
}
</script>

<form>
<select multiple onChange="doit(this)">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
<option value="5">Option 5</option>
<option value="6">Option 6</option>
<option value="7">Option 7</option>
<option value="8">Option 8</option>
</select>
</form>

In a flash form, you'd have to roll your own action script to do it. I seem
to recall that actionscript has something like... selectedItems for a
dropdown list. That may return the number of selected items and make it
easier but I'd have to check that to make sure. Else, you'd have to do
basically the same thing that the javascript is doing above... loop over
each option and check it's 'selected' status while keeping a 'count' of how
many are selected. As soon as too many are selected, alert() the user and
deselect the rest.

ThatÂ’s just quick and dirty though... ill probably think of a smoother way
as soon as I hit send ;^)          

 
...:.:.:.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com
-----Original Message-----
From: Saturday (Stuart Kidd) [mailto:[EMAIL PROTECTED] 
Sent: Sunday, December 04, 2005 4:00 PM
To: CF-Talk
Subject: Constraining cfselect

Hi guys,

Does anyone know how to constrain the amount of selections in a  
cfselect (multiple)?  And more so especially in a flash form.

Thanks,

Saturday






~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:226057
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to