I'm struggling with the following problem. I use the jQuery autocomplete plugin to get a list of suggested values from the server. The list would look like this:
Username1|UserId1 Username2|UserId2
So if I start typing "U", a list of "Username1"
and "Username2"
pops up, as expected. I could chose the first item and the <input>
's value would become "Username1"
, but what I really want to send to the server is the user ID.
Can I somehow get a hold of the ID that is following the user name? I intend to do the form post on change of the text box. Maybe I'm just too blind to see it in the docs or to find it on Google?
Use the result
method of the autocomplete
plugin to handle this. The data is passed as an array to the callback and you just need to save data[1]
somewhere. Something like this:
$("#my_field").autocomplete(...).result(function(event, data, formatted) {
if (data) {
$("#the_id").attr("value", data[1]);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With