Is it possible to set limit in multiple selection dropdown list?

I am using a multiple selection drop-down list in my site.This is working properly and we can select more than one options from that list.But I want select only 3 options from that list.Is it possible to set limit for that??

I am using the code from http://www.aleixcortadellas.com/main/2009/03/20/492/

Answers


use jQuery and following click function, it will help

$(document).ready(function() 
{
    $('#slectboxid option').click(function() 
    {
        var items = $(this).parent().val();
        if (items.length > 3) {
                       alert("You can only select 3 values at a time");
           $(this).removeAttr("selected");
        }
    });
   });

Edit: use .prop() instead of .removeAttr(),.removeAttr() is deprecated in newest jQuery libraries


In formsubmit.php change line 3 with the following line :

if (isset($options) && count($options) == 3) {

Then modify line 26 with the following :

echo 'Please select exactly 3 options';

Need Your Help

How to organize webdriver project in eclipse?

eclipse webdriver project-structure

I've started a few WebDriver projects in Eclipse Juno but i'm not satisfied with my structure, i think is to stupid and not efficient at all.

Round large non-decimal numbers, up and down with php

php

How do I round larger numbers in php.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.