This question is locked. New answers and comments are not allowed.
Dear all,
I've been spending some time trying to fix the underneath ambiguity, I reckon it's not a bug or error but just due to my lack of understanding on the nature of SQLite, hope someone can kindly point me to the right direction.
What I'm trying to achieve is, in the following functionA, I'll return a value to the variable "realpw" in which the value is obtained by a function from SQLite database called app.logincheck. I also used an alert to check value. However, the problem occurs here, the alert(realpw) always reveal as undefined... In fact, I also have an other alert in my app.logincheck function to make sure when the db is opened (see code below), and the second alert occured only after the functionA is finished.
Simply put, I was expecting app.logincheck to fire inside functionA. But what it can turn out is firing after functionA, any thought? Appreciate in advance for anyhelp!
functionA = function(){
$('#login').submit(function () {
var realpw = app.logincheck($('#userName').val());
alert(realpw);
if (realpw === String($('#pwd').val())){
//Some functions that are not relevant here.
}
else{ alert('Invalid Login Credentials.'); }
return false;
});
},
//SQLite javascript from other page
app.logincheck = function(drivername){
var render = function (tx, rs){
var row = rs.rows.item(0);
var realpw = String(row.Password);
return realpw;
}
var db = app.db;
db.transaction(function(tx) {
tx.executeSql("SELECT ID, DriverName, Password FROM table1 WHERE DriverName=? ORDER by ID DESC", [drivername],
render,
app.onError);
});
}
I've been spending some time trying to fix the underneath ambiguity, I reckon it's not a bug or error but just due to my lack of understanding on the nature of SQLite, hope someone can kindly point me to the right direction.
What I'm trying to achieve is, in the following functionA, I'll return a value to the variable "realpw" in which the value is obtained by a function from SQLite database called app.logincheck. I also used an alert to check value. However, the problem occurs here, the alert(realpw) always reveal as undefined... In fact, I also have an other alert in my app.logincheck function to make sure when the db is opened (see code below), and the second alert occured only after the functionA is finished.
Simply put, I was expecting app.logincheck to fire inside functionA. But what it can turn out is firing after functionA, any thought? Appreciate in advance for anyhelp!
functionA = function(){
$('#login').submit(function () {
var realpw = app.logincheck($('#userName').val());
alert(realpw);
if (realpw === String($('#pwd').val())){
//Some functions that are not relevant here.
}
else{ alert('Invalid Login Credentials.'); }
return false;
});
},
//SQLite javascript from other page
app.logincheck = function(drivername){
var render = function (tx, rs){
var row = rs.rows.item(0);
var realpw = String(row.Password);
return realpw;
}
var db = app.db;
db.transaction(function(tx) {
tx.executeSql("SELECT ID, DriverName, Password FROM table1 WHERE DriverName=? ORDER by ID DESC", [drivername],
render,
app.onError);
});
}