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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:31:01+00:00 2026-05-25T19:31:01+00:00

This code is inside a jquery mobile form. It adds up the numbers and

  • 0

This code is inside a jquery mobile form. It adds up the numbers and displays the total in a disabled text box. When the the total is 100, the continue (submit) button is enabled.

The session var code properly puts in zeroes when there isn’t a value.

Problem:
Sometimes people will type a number after the zero (eg: 0100).
It seems like this, combined with erasing a number will cause the numbers not to add up properly.

I could use your assistance with:
Getting rid of the random bugginess in calculating the total, especially when the value is cleared. Should I be using parseInt instead?

Thanks in advance.

 <script>
$(document).ready(function() {  
<?php 
if (!isset($_SESSION['num1'])) {   
    echo "$('#num1').val(0);";  
}
if (!isset($_SESSION['num2'])) {   
    echo "$('#num2').val(0);";  
}
if (!isset($_SESSION['num3'])) {   
    echo "$('#num3').val(0);";  
}
if (!isset($_SESSION['num4'])) {   
    echo "$('#num4').val(0);";  
}
?>  

 //to handle previously entered values if back button used: <br/>

var tot = ($('#num1').val() - 0) + 
    ($('#num2').val() - 0) + 
    ($('#num3').val() -0) + 
    ($('#num4').val() - 0);
    $('#total').val(tot);
    if (tot==100) {
       $('#continue').removeAttr('disabled');            
    } else {
       $('#continue').attr("disabled","disabled");             
    }

     //to handle numbers on update.  
    $('input[name^="int"]').keypress(function() {
        var tot = ($('#num1').val() - 0) + 
            ($('#num2').val() - 0) + 
            ($('#num3').val() -0) + 
            ($('#num4').val() - 0);
            $('#total').val(tot);
            if (tot==100) {
               $('#continue').removeAttr("disabled");
            } else {
               $('#continue').attr("disabled","disabled");
            }

       });
  • 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-25T19:31:01+00:00Added an answer on May 25, 2026 at 7:31 pm

    try with parseInt($('#num').val(),10) instead of $('#num').val() - 0 to transform the strings to numbers

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

Sidebar

Related Questions

I have this code inside the success function of a jQuery ajax call success:
I have this code inside http://www.mysite.local/js/site/functions.js : $.getScript('/js/common/jquery.jsonrpc.js', $.jsonRPC.setup({ endPoint: '/api/accounts', namespace: 'mynamespace' })
I have this code inside a class that is used by an application and
I have ASP.Net code similar to the following (this is inside a FIELDSET): <ol>
This code is executed by many way. When it's executed by the form button
trying to create a form inside a modal dialog. But i would like this
I am generating events on fullCalendar with this code <script type=text/javascript> $(document).ready(function() { $('#calendar').fullCalendar({
I have a problem displaying the autosuggest box inside a jQuery dialog. The auto
This code in JS gives me a popup saying i think null is a
This code is from Prototype.js . I've looked at probably 20 different tutorials, and

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.