开发者

fcbkcomplete, how to obtain all the values after adding or updating the Input

开发者 https://www.devze.com 2022-12-22 15:05 出处:网络
I\'m interested in using fcbkcomplete, which has: onselect – fire event on item select. onremove – fire event on item remove

I'm interested in using fcbkcomplete, which has:

  • onselect – fire event on item select.
  • onremove – fire event on item remove

What I'd like to happen for those two events is to alert a list of the IDs/values of the items in the input box.

Can you help me u开发者_如何转开发nderstand how to get these values?

Thanks


Since the plugin is tied to the actual select element, not the option elements inside, you should be able to write a function that just alerts out all option details of the contained options of the parent select. Maybe something like:

$("#select").fcbkcomplete({
       onselect: function() {
           var optionList;
           $("option",this).each(function() {
               optionList += $(this).attr("id") + " : " + $(this).val() + "\n";
           });
           alert(optionList);
       }
});


Checks if an item exists in the DB in this case a user.

$(document).ready(function () {
    $("#users").fcbkcomplete({
        json_url: "yoururl.php",
        cache: false,
        filter_case: false,
        filter_hide: true,
        complete_text:"'.get_lang('StartToType').'",
        firstselected: true,
        onselect:"check_users",   //<----- important
        filter_selected: true,
        newel: true
    });
});

Hewe we check if users exists in the DB

function check_users() {
    //selecting only "selected" users
    $("#users option:selected").each(function() {
        var user_id = $(this).val();        
        if (user_id != "" ) {            
            $.ajax({ 
                url: "my_other_url_to_check_users.php", 
                data: "user_id="+user_id,
                success: function(return_value) {
                    if (return_value == 0 ) {
                        alert("UserDoesNotExist");                        
                    }                    
                },            
            });                
        }        
    });
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号