Only the last run in a for loop in Javascript works

Posted by Mengfei Murphy on Stack Overflow See other posts from Stack Overflow or by Mengfei Murphy
Published on 2012-09-25T15:36:18Z Indexed on 2012/09/25 15:37 UTC
Read the original article Hit count: 283

Filed under:
|
|

Here is a for loop written by Javascript. It is trying to apply queries for websql.

for (var i = 0; i < 10; i++){
    db.transaction(function (tx){
    tx.executeSql('INSERT INTO ProjSetsT (ProjID) VALUES (?);', [i]);
    });
}

The attempt is obvious, I tried to add values "0, 1, 2, ... 9" into column ProjID in table ProjSetsT. It does not work. I only got the last element, i.e. "9" inserted, but not the first eight numbers.

Is there any syntax mistakes?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html5