1

I have an autocomplete snippet which retrieve's City names based on your search term.

For example the search term s would print:

enter image description here

So if I would use:

var f = [];
$.each(a.RESULTS, function (a, b) {
    f.push(b.name /* + b.zmw */)
});
b(f)

I would get printed the name of every city.

Live Example: http://jsfiddle.net/muWah/18/

How could I print/console.log() the zmw value of each city whenever I click on it.

So when I click on Serbia, I should get printed 000RB.1.99999

1 Answer 1

3
$.each(a.RESULTS, function (a, b) {
   f.push({label: b.name, value : b.zmw})
});

You can push a new object, with a label and value. Label is what's picked up for auto-complete, and value is what appears in the input when selected.

DEMO: http://jsfiddle.net/muWah/21/

If you wanted to just have the zmw reference in the console, rather than printed out in the input, you can add more properties to the object you passed through. For example:

$.each(a.RESULTS, function (a, b) {
    f.push({label: b.name, value : b.name, zmw : b.zmw})
});

Then b.item.zmw would be what you'd print out in your console, but the name/value would still be "Serbia" (or whatever you click on)

DEMO: http://jsfiddle.net/muWah/24/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.