Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7497161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:57:33+00:00 2026-05-29T18:57:33+00:00

I am in mobile app. I have a function that create a dynamic checkbox

  • 0

I am in mobile app.

I have a function that create a dynamic checkbox (getItem1) and inside this function I call another one that update sqlite .

function getItem1(flatname, flatdescription) {

    $(document).ready(function(){
    $('#Code').empty();
    $('#displayflat article3').empty();
    $('#displayflat article1').empty();
    $('#displayflat article2').empty();
    $('#shares').val('');
    });
        var gtotal=0;
        var total = 0;
        var payment = 0;
        var previouspayments = 0;
        var sofeilon = 0;
        var total1 = 0;
        var payment1 = 0;
        var previouspayments1 = 0;
        var sofeilon1 = 0;
        var len = 0;
        var list = $('#Code'),
            allbarcode = [],
            my = {},
            barcode = [],
            barcodeamount = [],
            barcodeprevious = [],
            items = [];

        $.mobile.notesdb.transaction(function(t) {
            t.executeSql('SELECT barcode, buildingcode, buildingaddress, flatname, flatdescription, entryseason, period, amount, pastpayments, todaypayments, paydate, receiptno FROM bill WHERE flatname = ? AND flatdescription = ?',
            [flatname, flatdescription],
            function(t, resultflatname) {
                var i,
                    ib,
                    len = resultflatname.rows.length,
                    row = 0,
                    rowprev = 0,
                    rowb = 0;

                for (i = 0; i < len; i += 1) {
                    row = resultflatname.rows.item(i);

    if (row.amount > row.todaypayments + row.pastpayments) {
                    if (row.receiptno == 0){
                        items.push('<input type="checkbox" name="code_'+ i +'" id="code_'+ i +'" value="' + row.amount + '" previous="' + row.pastpayments + '" barcode="' + row.barcode + '" todayp="' + row.todaypayments + '"/><label for="code_'+ i +'">' + row.period +'..........'+ row.amount+'</label></br>');
                    } else {
                    if ((row.receiptno > 0) && (row.amount > row.todaypayments + row.pastpayments)){
                        items.push('<input type="checkbox" name="code_'+ i +'" id="code_'+ i +'" value="' + row.amount + '" previous="' + row.pastpayments + '" barcode="' + row.barcode + '" todayp="' + row.todaypayments + '"/><label for="code_'+ i +'">' + row.period +'..........'+ row.amount+'</label></br>');


                    }
    }
                }
                        allbarcode[i] = row.barcode;
    //                  barcodeamount[i] = row.amount;
    //                  barcodeprevious[i] = row.pastpayments;
                        previouspayments1 = previouspayments1 + row.pastpayments;
                        previouspayments = previouspayments1.toFixed(2);
                        sofeilon1 = sofeilon1 + row.amount;
                        sofeilon = sofeilon1.toFixed(2);
                        total1 = sofeilon - previouspayments;
                        total = total1.toFixed(2);

                    list.html(items.join('\n'));

                $('#displayflat h1').text(row.flatname);
                $('#displayflat article').html('<h2>Flatname : ' + row.flatdescription + '</h2>');
                if (total != 0){
                    $('#displayflat article1').html('<p>Total : ' + total + '</p>');
                    $('#displayflat article2').html('<p>Months Total : ' + sofeilon + '</p>');
                }
                if (previouspayments != 0) {
                    $('#displayflat article3').html('<p>Previous Payments : <font color="red">' + previouspayments + '</font></p>');
                }
        }

                function calcTotal() {
                    $("input:checked").each(function() {
                        var value = [$(this).attr("value")]-[$(this).attr("previous")];
                        payment = payment + parseFloat(value); //total = total + value          
                    });
                }

                function barcodeTotal() {
                    barcode = [];
                    barcodeamount[i];
                    barcodeprevious[i];
                    $("input:checked").each(function(i) {
                        barcode[i] = $(this).attr("barcode");
                        barcodeamount[i] = $(this).attr("value");
                        barcodeprevious[i] = $(this).attr("previous");
                    });
                }

                calcTotal();
                $("#Payment").html('<p class="total">Total Payment: <strong>' + payment.toFixed(2) + '</strong></p>');

                $("input:checkbox, input:radio").click(function() {
                    payment = 0;
                    calcTotal();
                    $("p.total").html("Total Payment: <strong>" + payment.toFixed(2) + "</strong>");
                });

                $('#shares').keyup(function(){
                    payment = 0;
                    calcTotal();
                    gtotal = ($('#shares').val() * 1) + payment;
                    gtotal = gtotal.toFixed(2);
                    $("p.total").html("Total Payment: <strong>" + gtotal + "</strong>");
                });


                $('#shares').keyup(function(){
                    $("input:checkbox, input:radio").click(function() {
                        payment = 0;
                        calcTotal();
                        gtotal = ($('#shares').val() * 1) + payment;
                        gtotal = gtotal.toFixed(2);
                        $("p.total").html("Total Payment: <strong>" + gtotal + "</strong>");
                    });
                }); 

                $("#pay").click(function(e) {
                    barcodeTotal();
                    updateItem(payment.toFixed(2), gtotal, barcode, barcodeamount, barcodeprevious, allbarcode);
                });

            })
        });
}

and the code of updateItem. I use alert just to watch how many times executed.

function updateItem(payment, gtotal, barcodetotal, barcodeamount, barcodeprevious, allbarcode) {
alert(allbarcode);
alert(barcodeamount);
alert(barcodeprevious);
    var i,
        j,
        len = barcodetotal.length,
        lenall = allbarcode.length,
        today,
        receiptno,
        row = [],
        barcodeamount,
        barcodeprevious,
        enanti = 0,
        newbarcode,
        pasttotal,
        minimum = 0,
        myrow;

    $.mobile.notesdb.transaction(function(t) {
        t.executeSql('SELECT userid, name, receiptno FROM collector', 
            [], function(t, resultcollector) {
                myrow = resultcollector.rows.item(0);
                receiptno = myrow.receiptno + 1;
                t.executeSql('UPDATE collector SET receiptno = ?', [receiptno]);

                if (payment > 0 && gtotal == 0) {
                    for (i = 0; i < len; i += 1) {
                        row = barcodetotal[i];
                            for (j = 0; j < lenall; j += 1) {
                                if (allbarcode[j] == row){
                                    var place = j;
                                }
                            }
                        allbarcode.splice(place, 1);
                        barcodeprevious.slice(place, 1);

                        today = barcodeamount[i] - barcodeprevious[i];
                        var billtoday = barcodeamount[i];
                        t.executeSql('UPDATE bill SET pastpayments = ?, receiptno = ?, paydate = date("now") WHERE barcode = ?', [billtoday, receiptno, row]);
                        t.executeSql('INSERT INTO billpayments (barcode, amount, collectorid, receiptno) VALUES (?,?,?,?)',
                            [row, today, myrow.userid, receiptno]);
                    }
                }


                    if (gtotal > 0) {   
                        enanti = gtotal - payment;
                        //alert(enanti);
                        var minimum = Math.min.apply( null, allbarcode );
                        alert(minimum);
                        t.executeSql('SELECT barcode, amount, pastpayments, todaypayments FROM bill WHERE barcode = ?',
                            [minimum], 
                            function(t, previousp) {
                                var myr = previousp.rows.item(0);
                                var todaypp = myr.pastpayments + enanti;

                                t.executeSql('UPDATE bill SET pastpayments = ?, todaypayments = ?, receiptno = ?, paydate = date("now") WHERE barcode = ?', [todaypp, enanti, receiptno, minimum]);
                                t.executeSql('INSERT INTO billpayments (barcode, amount, collectorid, receiptno) VALUES (?,?,?,?)',
                                    [minimum, enanti, myrow.userid, receiptno]);
                        });
                    }






                    $.mobile.changePage('#display', 'slideup', false, true);
            })
    });

}

When getItem1 executed for the first time everything is OK.

For the second time of getItem1 the updateItem executed I think twice.

The third time of getItem1 the updateItem 3 times and so on.

After all that I cannot watch if the data are ok…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T18:57:35+00:00Added an answer on May 29, 2026 at 6:57 pm

    You’re hooking up your click event more than once. Each time through you need to remove the click event.

    Change your line for:

    $("#pay").click(function(e) {
    

    to:

    $("#pay").unbind('click').click(function(e) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mobile app that is using LinqToDatasets to update/insert into a SQL
we are creating one jQuery mobile app in that app, I have to bind
I have a windows mobile app (mymobiler) that i am trying to install and
I have a mobile app webservice client that connects to a WCF webservice(on my
I am working on a mobile app and I have an initial page that
I have a simple web mobile app that is calculating values in given fields.
I have a mobile app that I developed using PhoneGap (and html/css/javascript) and there
I have a simple mobile app in Titanium that I'm using to debug the
I have a Window Mobile app where the forms use keypreview and post the
I have been working on a Windows Mobile app for a little while now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.