SitePoint Sponsor

User Tag List

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

    Evaluate row before inserting new row

    I'm using the following to successfully insert a row in a database at the click of a button. (The filename and title are bookmark data. The title will appear on a bookmark button on a page showing all the app's bookmarks, and the button will take you to the filename's page. A Remove button at right will delete the row's data.):

    HTML Code:
    function insertRow() {
    db = window.openDatabase("Database", "1.0", "BOOKMARKS4", 200000);
    db.transaction(function(tx) {
    	var id = document.title, filename = window.location.pathname, title = document.title;
    	tx.executeSql("insert into BOOKMARKS4(id, filename, title) values(?,?,?)", [id, filename, title]);
    	}, errorCB, successCB()); alert('Bookmark added.');
    }
    However, I want to make sure the same filename and title data is not inserted again and again, which is occurring now. I'd like an alert to show up declaring that the page has already been bookmarked.

    The following alteration did not work (actually it prevented the insertRow function from working):

    HTML Code:
    function insertRow() {
    db = window.openDatabase("Database", "1.0", "BOOKMARKS4", 200000);
    var filename;
    if (filename.length > 1) {alert('You have already bookmarked this page'); return;}
    else {
    db.transaction(function(tx) {
    	var id = document.title, filename = window.location.pathname, title = document.title;
    	tx.executeSql("INSERT into BOOKMARKS4(id, filename, title) VALUES(?,?,?)", [id, filename, title]);
    	}, errorCB, successCB()); alert('Bookmark added.');
    	}
    }
    What's the correct way to evaluate whether a cell is already populated, and execute on that basis?

  2. #2
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,388
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Frankly, I don't know if this is even possible.


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
  •