How to find jQuery DropDownCheckList of selected items - jQuery syntax issue

I am working on an ASP.Net webpage that will use the jQuery Dropdown checklist ( http://code.google.com/p/dropdown-check-list/ ). I'm pretty inexperienced with JavaScript and brand new to jQuery.

What I want to do is collect the values ​​of the selected items every time the checkbox is checked or unchecked.

Here is what I still have:

var values = "";
$("#s1").change(function () {
     $("#s1").dropdownchecklist(function(selector) {
          for (i = 0; i < selector.options.length; i++) {
               if (selector.options[i].selected && (selector.options[i].value != "")) {
                    if (values != "") values += ",";
                    values += selector.options[i].value;
               }
          }
     });
});

I think the problem is in the third line, but I don’t know exactly what is wrong.

If anyone could point me in the right direction, I would appreciate it. Thanks in advance.

Reply to zod ... Thanks, that was pretty much exactly what I needed. However, I still have some kind of syntax error. Here is my code:

var values = "";
$("#s1").change(function () {
     $("#s1 option:selected").each(function () {
          if (values != "") values += ",";
          values += $(this).value();
     });
     alert(values);
});

, JQuery Dropdown , - .

, - , JavaScript jQuery? , Visual Studio intellisense. - JavaScript jQuery?

Ender... . . , . , , zod, , , , .

.

+3
2

, , . .change() .val() . :

$(function() {
    $("#s1").dropdownchecklist();

    $('#s1').change(function() {
        alert($(this).val());
    });
});

- : http://jsfiddle.net/Ender/ZsMc4/

+6

Source: https://habr.com/ru/post/1773907/


All Articles