I want to use the users entered value into the input being affected by autocomplete’s widget, hope the following is self-explanatory of what I want to achieve:
source: $(this).val()
I think $(this).val() won’t work because source expects an object?
I’m new to JavaScript, thanks.
$(".myinput").autocomplete({
source:$(this).val()
});
I think you are using the
sourceargument incorrectly for jQuery UI’s autocomplete.$(this).val()will get the current value out of the$(this)DOM object (assuming that’s what it’s pointing to).Instead the
sourceargument is supposed to be pointing to a source of possible completions for the input. As an example from the jQuery UI websiteAs you can see from this example,
sourcepoints to an array of possible tag values that will be autocompleted when the user starts typing.To address my new understanding of the OP’s question:
To add the user’s current entry into the autocomplete, you could use code like the following:
This would need to be called every time the input changes (using the
keypressevent might be helpful for this.)