I have created an array which will store dynamic values coming from DB. When I print the array inside the transaction function it is printing. when I tried to print out side I didn't get the values. I have declared the array globally. what is the problem, my code is as follows;
function sendCategoryDetails() {
var selected_category = $('#select-choice :selected').val();
alert("control : " + selected_category);
var mycoodinatesDetails;
var myLocation = new Array();
var db = window.sqlitePlugin.openDatabase({name: "MYDB"});
db.transaction(function (tx) {
tx.executeSql("select Location from Locationlog WHERE Category = '"+selected_category+"';", [],
function (tx, res) {
for (var i = 0; i < res.rows.length; i++) {
myLocation[i] = res.rows.item(i).Location;
}
alert (myLocation +" length : "+ myLocation.length); // Values are printing
});
});
alert (myLocation +" length : "+ myLocation.length); // values are not getting, It showing the length is 0
}
Any suggestions?