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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:43:14+00:00 2026-06-02T07:43:14+00:00

so I have a very simple script I’m writing to be a calculator so

  • 0

so I have a very simple script I’m writing to be a calculator so clients can see how much a service will cost, and then update the result based on changes to the text inputs. problem is after the first go around it stops calculating the values correctly. Here it is, help appretiated.

<script>
$(function(){


var one=0;
var two=0;
var three=0;
$("input:text").change(function(){
if($(this).val() == $('#first').val())
{ 
 one = parseInt($(this).val());



}
 else if($(this).val() == $('#second').val()){

two = parseInt($(this).val());

 }
 else if($(this).val() == $('#third').val()){

three = parseInt($(this).val());

 }

});


$('input:text').change(function(){

$('#result').text(one+two+three);


});


});


</script>

and the form:

<div id="container">
<form action="something.html" id="subit">
<label for="first">put numbers</label><input type="text" id="first"/>
<label for="second">more numbers</label><input type="text" id="second" value="0"/>
<label for="third">and more numbers</label><input type="text" id="third" value="0"/>
<input type="submit" />
</form>
<div id="result"></>
</div>
  • 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-06-02T07:43:15+00:00Added an answer on June 2, 2026 at 7:43 am

    Try this code

    $(document).ready(function() {
        var textboxes = $("#container input:text");
        textboxes.on("keyup", function() {
            var amt = 0;
            textboxes.each(function() {
                amt += +$(this).val();
            });
            $("#result").html(amt);
        });
    });​
    

    Working Fiddle: http://jsfiddle.net/naveen/87p53/


    As for your code, change these things in your code

    a. Compare ids and not values, its much safer that way.
    b. Remove the second change function. Not needed at all.

    $(function() {
        var one = 0;
        var two = 0;
        var three = 0;
        $("input:text").change(function() {
            if (this.id == "first") {
                one = parseInt($(this).val());
            }
            else if (this.id == "second") {
                two = parseInt($(this).val());
            }
            else if (this.id == "third") {
                three = parseInt($(this).val());
            }
            $('#result').html(one + two + three);
        });
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At the moment I have a very simple script. If I type the commands
I have a very simple python script that should scan a text file, which
I have a very simple jQuery script.. all I want it to do is
I have a very simple Powershell v1.0 script to kill processes by name: $target
I have written a very very very simple!! script in php. header redirection not
I have a very simple webforms app that will allow field techs to order
I'm trying to wrap my head around MSBuild. I have a very simple script
I have a very simple perl script that moves files (don't ask why i
I have a very simple php ldap script that is only failing when running
I have a very simple file upload PHP script. I am testing with a

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.