0

I'm checking out the sqlite and html5 using Javascript, heres the code I'm using to create, my DB, create my table and insert values from 3 text boxes that I have

function Add2DB() 
{
    var Tname = document.getElementById('txtName').value;
    var Tprice = document.getElementById('txtPrice').value;
    var Tqty = document.getElementById('txtQTY').value;
    db.transaction(function (tx){
        tx.executeSql('INSERT INTO foo (name,price,qty) VALUES(?,?,?)',[Tname,Tprice,qty]);
        tx.executeSql('SELECT * FROM foo', [], function (tx, results){
            var len = results.rows.length;

            //For statements not allowed, just bring back first item in db
            alert(results.rows.item(0).text)
        });
    });
}

The problem I'm having is that whenever I iterate through this, It just says Object object. I think it is a Javascript problem I'm having, I'm not certain though

tx.executeSql('INSERT INTO foo (name,price,qty) VALUES(?,?,?)',[Tname,Tprice,qty]);

This line might not be right either and may not be actually inserting the mapped values right. Can someone please shed some light on this. Any help, or ideas would help me greatly. Thank you.

0

1 Answer 1

1

Rather than an alert, if you use console.log (requiring Firefox with Firebug or a webkit-based browser) you can easily see more detail in what you're working with.

Try console.log("Results row: %o", results.rows.item(0).text);

If it is an object you'll be able to see into the object and better understand what it is. You'll need to look in the javascript console in those browsers.

Sign up to request clarification or add additional context in comments.

3 Comments

I'll note that I'm going to go with Tim's response above though. Mine may better give you better information about the error, but I think his might actually point out the actual error.
well good news is there is content w/ the correct data wrapped up inside the Object. Now I have to figure out how to pull it out.
Thank you, I got the data back I needed. I made another variable, called and the prop named I wanted and it returned: var obj = results.rows.item(i); alert(obj.name);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.