SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    alerts show correct numbers; innHTML shows "undefined"

    The alerts fire with the correct values, but the innerHTMLs of ID and data show undefined. Why would that be? data_num shows the correct number (100) in the innerHTML:

    Code:
         	tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)", ["test", 100], function(tx, res) {
          		alert("1. insertId: " + res.insertId + " [should be 1]");
            	db.transaction(function(tx) {
              	tx.executeSql("SELECT data_num from test_table;", [], function(tx, res) {
                	alert("2. res.rows.length: " + res.rows.length + " [should be 1]");
                	alert("3. res.rows.item(0).data_num: " + res.rows.item(0).data_num + " [should be 100]"); 
                	alert("Starting display of table...");
    // my addition START 	
            			document.getElementById("output").innerHTML = 
            			"<table><tr><td>id = " + res.rows.item(0).id + 
            			"</td><td>data = " + res.rows.item(0).data + 
            			"</td><td>data_num = " + res.rows.item(0).data_num + 
            			"</td></tr></table>";
    // my addition END
                }); // SELECT
              }); // db.function(tx)
    
            }, function(e) { // function(tx, res)
            alert("ERROR: " + e.message);
          });// INSERT
    Steve Husting

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,272
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StevenHu View Post
    data_num shows the correct number (100) in the innerHTML
    So, the innerHTML shows the correct data_num? But not the correct id or data? Because in your alerts, you confirmed that data_num is what you expected, but you didn't confirm that id or data are what you expected.

    EDIT: Also, your SQL select statement is explicitly selecting only data_num, which would explain why neither id nor data would be in the result.
    "First make it work. Then make it better."

  3. #3
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    So, the innerHTML shows the correct data_num? But not the correct id or data? Because in your alerts, you confirmed that data_num is what you expected, but you didn't confirm that id or data are what you expected.

    EDIT: Also, your SQL select statement is explicitly selecting only data_num, which would explain why neither id nor data would be in the result.
    Thank you! I never saw that, obviously. (Not my code.)
    Steve Husting


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •