0

I am using the following tutorial to populate a dropdown menu from a json list: http://loopj.com/jquery-tokeninput/

I am particularly using the following code:

    $(document).ready(function() {
        $("#demo-input-local").tokenInput([
            {name: "Ruby"},
            {name: "Python"},
            {name: "JavaScript"},
            {name: "ActionScript"},
            {name: "Scheme"},
            {name: "Lisp"},
            {name: "C#"},
            {name: "Fortran"},
            {name: "Visual Basic"},
            {name: "C"},
            {name: "C++"},
            {name: "Java"},
            {name: "Taranto"}
        ]);

        $("#demo-input-local").change(function(){
            var city = // get the selected value on change
            console.log(city);
        });

    });

I want to be able to select the value as soon as a new option is selected

Naftali
  • 144,921
  • 39
  • 244
  • 303
Aessandro
  • 5,517
  • 21
  • 66
  • 139

2 Answers2

0

this.value holds the value of the selected item.

Naftali
  • 144,921
  • 39
  • 244
  • 303
0

Use:

$("#demo-input-local").change(function(){
        var city = $(this).val();
        console.log(city);
});

Demo: http://jsfiddle.net/FlameTrap/uAhGJ/

Josh
  • 2,835
  • 1
  • 21
  • 33