i have the following piece of javascript where i perform an sql query, and depending on the result i need to perform a second query. Although i manage using a closure to iterate proper values for the second query, i haven't been able to return the desired value back. I keep getting undefined.
        db.transaction(function(tx) {
            tx.executeSql('SELECT * FROM maintainance', [], function(tx, results){
                maintainance_length = results.rows.length;
                maintanance_query = results.rows;
                for (i = 0; i < maintanaince_length; i++) {
                    maintainance_title = maintanance_query[i].element;
                    var classAction = function(){
                        if(maintanance_query[i].code == '0'){
                            return 'no';
                        }else{
//over here i use the closure to iterate each seperate maintainance_title value
                            (function(maintainance_title){
                            db.transaction(function(tx) {
                            tx.executeSql('SELECT * from maintainance_history WHERE element = \''+maintainance_title+'\'',
                            [], function(tx, results){
                                if(results.rows.length > 0 && results.rows[0].action == '1'){
                                    return 'ok';
                                }else{
                                    return 'warn';
                                }
                            },function(tx, error){
                                    console.log(error);
                                    console.log(tx);
                            });});
                            })(maintainance_title);
                        }
                    }
                    historyIcon = "<div class=\""+classAction()+"\"></div>";
                }
                },function(tx, error){
                }
            );
         }); 
i have tested a few variations ovr ths code, but still the result would either be "undefined" of uncaught exception that classAction is not a function
 
    