I'm having trouble trying to get simple javascript to work together with jQuery UI. I'm using jQuery UI to power autocomplete for a set of form input elements, and while that is working satisfactorily, no JavaScript code I write works. Strangely enough, when I comment all the jQuery UI stuff out and just try to run my JavaScript, everything works perfectly!
Is there something in the jQuery UI code library is overriding my ability to use self-defined JavaScript functions?
And here's the script that is running my autocomplete.
<script>
var fruits = ['Apples', 'Oranges', 'Bananas', 'Grapes'];
$(function() {
$( ".input-box" ).autocomplete({
source: availableTags
});
});
</script>
So basically, as you can see, this code is running autocomplete on some input element (with class input-box) and the data/list-items in the autocomplete are taken from array fruits.
Awesome. This works well.
However, now I want for the value of the input element to be appended to the array fruits when it loses focus. So basically, you type "Pineapples", and when you shift focus from the input box (using onchange or another event trigger), "Pineapples" is added to array fruits and will start showing up in future autocomplete listings.
And so in every input element, I add onchange = "addValue(this.value)"
And so, the code for the function is something like
function addValue(value) {
fruits.push(value);
}
But it doesn't work. Even onchange = alert('Hi')
, i.e., basic javascript stuff doesn't work.
How do I do this?