Hello All this is my first time posting to this form so I hope my question is clear and concise.
I have a Html form :
[CODE] <form action=”” method=”post” id=”form”>
<input type=”Text” name=”userInput” value=””>
</form>
The user will enter in a name of a item and this name will be passed to a function :
[CODE]
function init(){
var input = document.forms[‘form’].elements[‘userInput’].value ;
}
Next I take the variable input and insert that into my sql statement which is suppose to query my data table and send back my bounds of the location of that item and zoom in.
[CODE]setTimeout(function() {
var sql = new cartodb.SQL({ user: ‘jnmn11’ });
sql.getBounds(“select * From stations where station_nm Like ‘” + input + “‘”).done(function(bounds) {
map.fitBounds(bounds)
});
}, 2000);
If I hard code the name in my script functions as expected however when trying to get the input box to send the user input to my function I am getting a Undefined error within the Url being sent:
sql?q=SELECT%20ST_XMin(ST_Extent(the…*%20From%20stations%20where%20station_nm%20Like%20’undefined’)%20as%20subq”
I used this site to create my form input function and am not quite sure if I am missing something?