Cannot assign value to a variable - Javascript

I am having trouble assigning the value of "$scope.returnPollings[i]" to "plrtn" during the loop. "$scope.returnPollings" is an object with a data and i can confirm there is a data in it when i console.log it.

    db.transaction (function(tx) {
        var sql = "INSERT INTO STATUSREPLY (reply, name, userCode, icon, target, repliedDate) VALUES (?, ?, ?, ?, ?, ?)";
        var len = $scope.returnPollings.length;
        var plrtn;                              
        for (var i = 0; i < len; i++) {
            plrtn = $scope.returnPollings[i]; // value is not being assigned here
            tx.executeSql(sql, [plrtn.message,, plrtn.userCode, plrtn.qWink,, plrtn.createdDate ], 
                    console.log('Status Inserted');
           },function(tx, error) {
                console.log('polling INSERT ERROR: ' + error.message);


I will be glad if anyone can help me


The answer is, that you are assigning more than once to the same variable. i would do this like this:

plrtn;//without var
        for (var i = 0; i < len; i++) {
            delete plrtn;
            plrtn = $scope.returnPollings[i]; // value is not being assigned here

Look at the value of $scope.returnPollings

var plrtn;  
for (var i = 0; i < len; i++) {

You get two values for $scope.returnPollings[0] In the Console you should be able to see the two (length) values of $scope.returnPollings[0] and $scope.returnPollings[1]




In your SQL you do not need to use plrtn.

Instead you could use:


Need Your Help

Why won't Hg let you push with patches applied?

mercurial mercurial-queue

I can't understand why Mercurial won't let me push when patches are applied. From my point of view, applied patches affect only the current workspace and pushing isn't influenced by the state of the

How to centre text in Sherlock Action Bar with icon and sliding menu

android android-actionbar actionbarsherlock slidingmenu

I am trying to implement an Action Bar on an Android Activity which implements Jeremy Feinstein's sliding menu and actionbarSherlock. The issue I am facing is to centre align the title text in the ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.