More

Cartodb search by column


I'm trying to implement a search box that uses my CartoDb data? My current code does not work.

Html:

    

My Map

Js:

function processFormData() { var input = document.getElementById("select-place").value; return input; } function main() { cartodb.createVis('map', 'https://testuser.cartodb.com/api/v2/viz/123456789/viz.json', { title: false, description: false, tiles_loader: false }) .done(function(vis, layers) { var userInput = processFormData(); var sql = new cartodb.SQL({ user: 'testuser' }); sql.getBounds("select * from testdb where name like ='%userInput%'").done(function(bounds) { map.fitBounds(bounds) }); var subLayer = layers[1].getSubLayer(0); createSelector(subLayer); }) .error(function(err) { console.log(err); }) } window.onload = main;

That code can't work, you need to put the logic on using the SQL API on the function called by the submit button (processFormData) and thatcreateSelectorcall is not defined anywhere.