1

I have a auto-complete textbox image attached with it below, user can select multiple skills, I want, user can select only 5 skills not more. how can i do this. My code

<script type="text/javascript">
    $(document).ready(function () {
        SearchText();
    });

    function SearchText() {
        $("[id*=ctl00_ContentMain_TextBoxSkills]").autocomplete({
            source: function (request, response) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: 'WebServiceSkills.asmx/GetAutoCompleteData',
                    data: "{'skill':'" + extractLast(request.term) + "'}",
                    dataType: "json",
                    success: function (data) {
                        if (data.hasOwnProperty("d")){
                            // Leave the .d behind and pass the rest of the JSON object forward.
                            response(Array.parse(data.d));
                           }
                        else
                            // No .d; no transformation necessary.
                            response(Array.parse(data.d));
                    },
                    error: function (result) {
                        alert("No Result Found");
                    }
                });
            },
            focus: function () {
                // prevent value inserted on focus
                return false;
            },
            select: function (event, ui) {
                var terms = split(this.value);
                // remove the current input
                terms.pop();
                // add the selected item
                terms.push(ui.item.value);
                // add placeholder to get the comma-and-space at the end
                terms.push("");
                this.value = terms.join(", ");
                return false;
            }
        });
        $("#ctl00_ContentMain_TextBoxSkills").bind("keydown", function (event) {
            if (event.keyCode === $.ui.keyCode.TAB &&
                    $(this).data("autocomplete").menu.active) {
                event.preventDefault();
            }
        })
        function split(val) {
            return val.split(/,\s*/);
        }
        function extractLast(term) {
            return split(term).pop();
        }
    }
</script>

Image is here: i want user can not add more than 5 skills, Screenshot

Aman
  • 132
  • 2
  • 12

0 Answers0