$('select[name="Subdivision"] option').click(function(o){
var c = 0, s = this.parentNode.options, i;
for(i=0;i<s.length;i++) {
if(s[i].selected) {
c++;
}
}
if(c > 10) {
this.selected = false;
}
});
On 2 March 2011 15:47, wavded <[email protected]> wrote:
> Got this code (jQuery 1.5.1 code), where csubs is the current selections.
> I want to prevent users from selecting more than 10. However I have a big
> list (1000+) and IE croaks at trying to restore the csubs (my guess is its
> traversing all the elements). Is there a way to just prevent a selection
> after 10 from happening? I tried preventing onchange, onclick... etc, and
> it still selects. I don't care if the solution is jQuery or whatever else,
> just looking for a solution. Thanks!
>
> var csubs = null;
> $('select[name="Subdivision"]').change(function(e){
> var tsubs = $(this).val();
> if(tsubs.length > 10){
> alert('Cannot select more than 10');
> $(this).val(csubs || []);
> } else {
> csubs = tsubs;
> }
> });
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]