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 7562771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:29:39+00:00 2026-05-30T13:29:39+00:00

I am in mobile app. I use a button that on click checks if

  • 0

I am in mobile app. I use a button that on click checks if gtotal is greater than total and alerts a message. Here is my code

        $("#pay").unbind('click').click(function(e) {
            barcodeTotal();
            if (gtotal > total){
                alert("Too much money");
                $('#shares').val('');
                payment = 0;
                gtotal = 0; 
                $("#Payment").html('<p class="total">Total Payment: <strong>' + payment.toFixed(2) + '</strong></p>');
                return false;
            }
            updateItem(payment.toFixed(2), gtotal, barcode, barcodeamount, barcodeprevious, allbarcode);
        });

I have the following problem. The alert pops up on every click without if statement check…

Where am i wrong?

please advice

this is total calculation

        for (i = 0; i < len; i += 1) {
            row = resultflatname.rows.item(i);
            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>');
            } 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>');
            }
        }
                allbarcode[i] = row.barcode;
                previouspayments1 = previouspayments1 + row.pastpayments;
                previouspayments = previouspayments1.toFixed(2);
                sofeilon1 = sofeilon1 + row.amount;
                sofeilon = sofeilon1.toFixed(2);
                total1 = sofeilon - previouspayments;
                total = total1.toFixed(2);

and this is gtotal calculation

        $('#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>");
            });
        }); 

and calctotal function

        function calcTotal() {
            $("input:checked").each(function() {
                var value = [$(this).attr("value")]-[$(this).attr("previous")];
                payment = payment + parseFloat(value); //total = total + value          
            });
        }
  • 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-30T13:29:41+00:00Added an answer on May 30, 2026 at 1:29 pm

    You should debug the variables gtotal and total to view their data types.

    console.log(gtotal, typeof(gtotal));
    console.log(total, typeof(total));
    

    If the values are strings the if-statement will return true as “76.40” is considered greater than “107.10”.

    Use parseFloat() to convert the strings to numbers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We've got a few pages that use the apple-mobile-web-app-capable meta tag (value=yes), but on
I'm trying to use Jquery Mobile for a web-app, and depending on what button
I have a Window Mobile app where the forms use keypreview and post the
Is there a way to make Windows Mobile not use the main phone app?
I have a windows mobile app (mymobiler) that i am trying to install and
I have a mobile app that is using LinqToDatasets to update/insert into a SQL
I have a mobile app webservice client that connects to a WCF webservice(on my
I'm using PhoneGap and JQuery Mobile. I'm trying to use custom button icons. I
I'm working on a web app, which I decided to use jQuery Mobile for
I am trying to use Appcelerator Titanium to build a mobile app. This app

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.