I’d like to pass values from other input fields on the form to an input with jquery autocomplete feature. I try several ways but none of them work. Here is an example of what I have so far:
html:
<input type="text" class="fieldname"/>
<input type="text" class="fieldname"/>
<input type="text" class="fieldname"/>
<input type="text" class="fieldname"/>
<input type="text" class="autofieldnames"/>
<input type="text" class="autofieldnames"/>
jquery:
$(".fieldname").each(function() {
$(this).blur(function() {
var fieldnames = $(".fieldname").map(function(){ return this.value; }).get();
});
$(".autofieldnames").each(function() {
$(this).autocomplete({ source: fieldnames });
});
If I manually set the fieldnames array (i.e. fieldnames = [“aaa”, “abc”];) autocomplete works but can’t pass the values of from other fields into an array for some reason.
It’s solved. FYI, this is what I come up with: