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

只愿长相守 提交于 2019-12-01 19:41:56

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';
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!