JQuery UI autocomplete value after mouse click - old value

I am using jQuery UI autocomplete widget. I need to use the selected text for further processing, immediately after the change, or select.

But when the user clicks the suggested value, the input value is transmitted.

$( "#autocomplete" ).autocomplete({
source: function( req, resp ) {
    $.post( "/echo/json/", {
        json: '["Test1", "Test2", "Test3", "Test4", "Test5"]',
        delay: 1
    }, function(data) {
        resp( data );
    }, "JSON" );
},
select: function (event, ui) { alert($(this).val())}
});

An example of this script: (try typing "tes" and select the mouse sentence)

http://jsfiddle.net/M3Yur/

I need to use an input value. change events use an input value, it should work in both cases when an autocomplete item is selected, but also when only a value is typed, so the warning is used only as an example.

How to get around this?

EDIT: I ended up using: $(this).val(ui.item.value).val(); these solutions always get the set value after the change event.

+3
2

:

select: function (event, ui) { alert($(this).val())}

:

select: function (event, ui) {alert(ui.item.value);}

: http://jsfiddle.net/M3Yur/4/

+4

ui , :

select: function (event, ui) { alert(ui.item.value); }
+2

All Articles