SitePoint Sponsor

User Tag List

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

    Need proper syntax

    I am using this button to insert data into a storage database:

    HTML Code:
    <div class="bookmark"><input type="button" class="addBM" value="Add Bookmark" onclick="insertRow('100', window.location.pathname, document.title)"></div>
    However, although the rows are being inserted, all the data is undefined. Here is the insert statement:

    Code:
    function insertRow() {
    db = window.openDatabase("Database", "1.0", "Bookmarks", 200000);
    db.transaction(function(tx) {
    	var id;
    	var filename = window.location.pathname;
    	var title = document.title;
    	tx.executeSql("insert into BOOKMARKS(id, filename, title) values(?,?,?)",[id, filename, title]);
    	}, errorCB,successCB()); alert('Bookmark added.');
    }
    What's the proper syntax to carry the data to the DB? There are no errors in the console, and the alert pops up at the right time.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    4 Thread(s)
    How about using the errorCB to show any errors that occur?

    Code javascript:
    function errorCB(tx, err) {
       alert('Error processing SQL: ' + err);
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,316
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I've been using:

    function errorCB(err) {
    console.log("Error processing SQL: "+err.code);
    }

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by StevenHu View Post
    I've been using:

    function errorCB(err) {
    console.log("Error processing SQL: "+err.code);
    }
    That could be why the problem then.

    The webdatabase specs show that the error callback has two parameters, the first being the transaction object, and the second being the error.
    http://www.w3.org/TR/webdatabase/#ex...sql-statements
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,316
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I do believe you nailed it, I see the words now! Now I've got to work on the Delete Row button, next, with its Unexpected token: } error.

    Thanks so much, Paul!


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
  •