Should be changed to 

    transaction.oncomplete = function ...

it plays nicer with concurrent transactions