How to get identifiers when value is selected in fcbkcomplete file? - Added jsfiddle

Please go to the violin below. I am trying to get the identifiers of the selected products in a field fcbkcompleteand show them as comma separated values ​​in a text box with id="interest". I wrote a function to achieve this, but it did not work. The function adds the identifier of the first value and does not accept the identifiers of other values ​​that are added to the multiple choice field.

http://jsfiddle.net/balac/xDtrZ/1/

I have added json.txt. it contains data such as

[{"key":"2", "value":"Canon Powershot "},{"key":"3", "value":"Fastrack Bag"},{"key":"4", "value":"Iphone 4 "},{"key":"5", "value":"Levis Jeans"},{"key":"7", "value":"Indig"},{"key":"8", "value":"Dashing Cars"},{"key":"9", "value":"dsdas"},{"key":"10", "value":"fsfs"}]

In the json value above, the value is the identifier that I want to display in the text box as comma separated values. value is the value that will be displayed in the drop-down list for selection.

when choosing values ​​from the drop-down list, I want the corresponding key to be added to the text field as comma-separated values.

The problem is that only the key of the first selected item is added to the text box.

I hope that I am concrete and said everything in detail. if anyone wants clarification, ask me, I will explain more.

+5
source share
2 answers

, . , - , , fcbkcomplete, .

$(document).ready(function() {
    $("#select3").fcbkcomplete({
        addontab: true,
        maxitems: 10,
        input_min_size: 0,
        height: 10,
        select_all_text: "select",
        onselect: clicker
    });
});

var clicker = function() {
    var selected = new Array();

    $('option', this).each(function() {
        selected.push($(this).val());
    });

    $('#interest').val(selected.join(', '));
};

.

. <option>'s select, fcbkcomplete, . , , .

, fcbkcomplete, -, id <option>'s - opt_vaQDzJU37ArScs818rc8HUwz9gm1wypP, . , , .

, :

$('option', this).each(function() {
    for (var i = 0; i < this.attributes.length; i++) {
        var pair = this.attributes[i].name + ': '
            + this.attributes[i].value;
        alert(pair);
    }
    selected.push($(this).val());
});

, fcbkcomplete.

JSON txt , , , . , , JSON <option> s. :

$(document).ready(function() {
    var clicker = function(e) {
        var selected = new Array();

        // using "this" here was out of context, use #select3
        $('option', $('#select3')).each(function() {
            selected.push(this.value);
        });

        $('#interest').val(selected.join(', '));
    };

    $("#select3").fcbkcomplete({
        json_url: "parseJSON.txt",
        addontab: true,
        maxitems: 10,
        input_min_size: 0,
        height: 10,
        select_all_text: "select",
        onselect: clicker
    }); 
});
+3

fcbkcomplete . , id. https://github.com/emposha/FCBKcomplete/issues/110 :

`//auto complete jquery starts here
     $("#box").fcbkcomplete({
                    width: 250,
                    addontab: true,                   
                    maxitems: 1,
                    input_min_size: 0,
                    height: 10,
                    cache: true,
                    filter_case: true,
                    filter_hide: true,
                    filter_selected: true,
                    newel: true,
                    filter_case:false,
                    onselect: function(item)
                    {
                        getting_value_dealer(item._value, item._id);
                    }
                });
    //auto complete jquery ends here
`
0

All Articles