I'm trying to call the Javascript variable elem after LIKE in the SQL statement so that the input text is used there. However the way I'm doing it doesn't work with the Sheetrock library I'm using (http://chriszarate.github.io/sheetrock/).
<!DOCTYPE html>
<html>
<body>
Enter Tracking Code: <input type="text" id="textbox_id">
<input type="button" value="Submit">
<table id="switch-hitters" class="table table-condensed table-striped"></table>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-sheetrock/1.0.1/dist/sheetrock.min.js"></script>
<script>
var mySpreadsheet = 'https://docs.google.com/spreadsheets/d/1_1elTo5zH1ew6KPYwoWtixX9hzFc8oxdRy5A0LWFkwg/edit#gid=0';
var elem = document.getElementById('textbox_id').value;
$('#switch-hitters').sheetrock({
url: mySpreadsheet,
query: "select A,B,C,D,E where A LIKE %"+elem+"%"
});
</script>
</body>
</html>
Since you updated your question here is updated answer. Check working jsfiddle: https://jsfiddle.net/r0sk7vtf/
you need to handle submit button click event and then call service
while spreadsheet api understand like without quotes, it doesn't work via sheetrock.js , so you need to use A like '9999%'
in your query
Snippet:
var mySpreadsheet = 'https://docs.google.com/spreadsheets/d/1_1elTo5zH1ew6KPYwoWtixX9hzFc8oxdRy5A0LWFkwg/edit#gid=0';
var button = $('#btn'), elem = $('#textbox_id')
button.on('click', function(e){
var v = elem.val();
$('#switch-hitters').sheetrock({
url: mySpreadsheet,
query: "select A,B,C,D,E where A like '" + v + "%'"
});
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With