1

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 understand how to get these values?

Thanks

dove
  • 20,469
  • 14
  • 82
  • 108
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012

2 Answers2

2

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);
       }
});
Anthony
  • 36,459
  • 25
  • 97
  • 163
  • This doesn't seem to work. Can you help me understand what the core of this is supposed to be doing? thxs – AnApprentice Mar 07 '10 at 01:58
  • Try it now. I made a false assumption that `this.id()` would return the id, which it doesn't. I fixed that. What it's doing is going through every option element in the select element you have the add on set to and adding "id : value" to a string and then altering that string at the end of the loop. – Anthony Mar 12 '10 at 08:09
  • Let me know if that fixed it, btw. – Anthony Mar 12 '10 at 08:11
  • @Anthony - what is the ".=" in the line: optionList .= ?? – leora Feb 19 '11 at 20:35
  • @Anthony - this gives me the results of EVERY select on my page.. not just the ones in this – leora Feb 20 '11 at 12:38
  • @ooo .= is from PHP and probably a typo, replace it with += – Chris S Mar 03 '11 at 19:42
  • @Chris S - thanks. this code above still gets EVERY select box on the page and not just the one with the fcbkcomplete so i am not sure why the answer was selected as correct. My guess is that in this example, this was the only select on the page. that being said, its not really the correct answer. – leora Mar 04 '11 at 13:10
  • @ooo have you tried out tag-it? http://plugins.jquery.com/project/tag-it it's a lot less fiddly – Chris S Mar 04 '11 at 14:04
0

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");                        
                    }                    
                },            
            });                
        }        
    });
}
Julio
  • 1,903
  • 2
  • 16
  • 19