0

I used a solution given by "Chrules" found in this discussion:buttons with no href, onclick etc

like this :

<button id="clickable" >Click Me!!</button>
 ......
$("#clickable").click(function(){
 // Send user to this link
   insertRecord(); //SQLite Code
  location.href = "game.html";
   // location.href = "http://www.takemehere.com"; });

So When i used the location.href like he putted it (= "http://www.takemehere.com";) The insertRecord() method is done with success (the object is added to the database)

But when I use the location.href = "game.html"; the game.html page is opened but the insertRecord() method is not done i tried to put the full path of game.html but the same problem persist Have you any idea please ? Thank u in advance

Community
  • 1
  • 1
Amira Manai
  • 2,599
  • 8
  • 40
  • 60

1 Answers1

2

I think insertMethod() calls some async functions to do database updating. So you should use a callback before doing anything else.

Something like this (i don't know what is inside of insertRecord method);

function insertRecord(callback) {
  // do all sorts of database job
  // when it's finished
  // fire your callback
  callback();
}

insertRecord(function() {
  location.href = "page.html";
});

EDIT: After your comment, i see you already have defined a function to run after sql which is loadAndReset(). So simply put location.href = "page.html" in that function, and it should work.

keune
  • 5,779
  • 4
  • 34
  • 50
  • function insertRecord() { db.transaction(function(tx) { tx.executeSql(insertStatement, [firstName.value], loadAndReset, onErrorInsert); }); – Amira Manai Apr 21 '12 at 09:14
  • function onErrorInsert(tx, error) { alert("Ce Login est utilisé choissez un autre"); resetForm(); } – Amira Manai Apr 21 '12 at 09:15