vgoklani
vgoklani

Reputation: 11786

How to use Twitter typeahead to open a new page after autocompletion

I'm using Twitter's Typeahead library, and just as a toy model question: how do I open a new page after a user makes a selection. For example, suppose the user selects "mercury" below, how do I then open this link "https://www.google.com/search?&q=mercury":

$('#input').typeahead([
{
name: 'planets',
local: [ "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune" ]
}
]); 

Upvotes: 0

Views: 151

Answers (1)

Brandon
Brandon

Reputation: 228

You would do something similar to this:

    $('#input').on('typeahead:selected', function(e, datum){
            window.location = '/some/directory/'+datum.id;
    });

If datum.id doesn't work try logging out datum inside the function to see what all you have access to:

    console.log(datum);

Upvotes: 1

Related Questions