Web Sql - Make select from ID

2

I'm trying to make a select from a ID that will be caught in the value of a option , I searched the net and saw that they put this inside a function, but when I put the function, the variable that should store the value, simply does not work anymore.

In this way the code works and even gets to the value, but it does not work in select of the DB, everything I tried to do always stops working.

    var myTest = document.getElementById("list").value;        
    db.transaction(function(tx) {
        tx.executeSql(
        'SELECT * FROM exercicios WHERE se_id = ?', [myTest],
            function(tx, results){
                var exlist = document.getElementById("exlist");

                for(var i = 0; i < results.rows.length; i++) {
                    var row = results.rows.item(i);
                    exlist.innerHTML += "<li>" + row.se_id + " - " + row.ex_nome + "</li>";
                }
            }
        );
    });
    
asked by anonymous 18.06.2014 / 03:17

1 answer

0

By chance is your se_id numeric? When you do:

var myTest = document.getElementById("list").value;

The value of myTest is a string. Using it in select will cause it to return no result if se_id is numeric. Try turning this value into an integer before using select :

var myTest = parseInt(document.getElementById("list").value, 10);

Example in jsFiddle .

    
18.06.2014 / 04:11