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

1
  • have you tried using set time out. Commented Apr 21, 2012 at 9:08

1 Answer 1

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.

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

2 Comments

function insertRecord() { db.transaction(function(tx) { tx.executeSql(insertStatement, [firstName.value], loadAndReset, onErrorInsert); });
function onErrorInsert(tx, error) { alert("Ce Login est utilisé choissez un autre"); resetForm(); }

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.