deckoff
deckoff

Reputation: 361

Store a webSQL result to a var to be used by other functions?

Here is the code:

speeddial.storage.findGroupName = function(id) {
      speeddial.storage.db.transaction(function(tx) {
        tx.executeSql('SELECT * FROM groups WHERE id = ?', [id], function (tx,results){
          alert(results.rows.item(0).title);
          return FolderName;
          }, 
          null);
      });
    }
function foo(results.rows.item(0).title){...

I want the result which is in the alert box - results.rows.item(0).title - to be stored in a variable and used in the next function... I am new to this, and probably cannot et the syntax right. The alert box gives me the expected result :)

Upvotes: 1

Views: 1283

Answers (1)

Paul Sweatte
Paul Sweatte

Reputation: 24617

Use the specified function name in place of the alert reference:

speeddial.storage.findGroupName = function(id) {
  speeddial.storage.db.transaction(function(tx) {
    tx.executeSql('SELECT * FROM groups WHERE id = ?', [id], function (tx,results)
      {
      foo(results.rows.item(0).title);
      return FolderName;
      }, 
      null);
  });
}

function foo(myresult){
    /*...*/
}

Upvotes: 2

Related Questions