I have this form:
<form>
<input type="text" class="name" id="name1">
<input type="text" class="name" id="name2">
<input type="text" class="name" id="name3">
...
<input type="text" class="name" id="name100">
<input type="submit" value="Send">
</form>
<script>
$(document).ready(function() {
var items = [
"",
];
$(".name").autocomplete({
source: items
});
$('.name').on('keyup', function(e) {
var txtVal = this.value;
items.push(txtVal);
});
});
</script>
What I’m trying to achieve is to have autocomplete with the value from the fields above. I used jquery autocomplete. The variable that stores the autocomplete options is called "items" and on keyup I pushed that value on the array. The result is a mess and somwhere I must’ve screw it. Here is a working end user scenario:
Step 1: Let’s say in the field #name1 I type Jon Doe
Step 2: When I go to #name2, I would like that after I type J to see an autocomplete option Jon Doe (the value from the above field).
Step 3: Let’s say I didn’t choose Jon Doe as autocomplete for #name2 so I typed Joanna Doe.
When I go to #name3, I should see Jon Doe and Joanna Doe as autocomplete options.
2
Answers
It looks like it was a bit simpler than I thought.
This might be what you are looking for:
Demo
If you wish, you can "exclude" the input from auto updating itself when typing: