adding or subtracting value when typing in textbox

 //         $(window).load(function() {
                   $(document).ready(function() {
                      //add functions here
                       $('input[id^="txtquantity"]').live('keyup', function() {
                       //  if (String($(this).val()).length < 1) return false;
                         getSum();
                       });
                 });
          $(document).ready(function() {
              getSum();
          });
function getSum() {

              var s = 0;
              $('input[id^="txtquantity"]').each(function() {
                  //if (String($(this).val()).length < 1) return false;
                  var v = $(this).val();

                  s = s + (isNaN(v) ? 0 : parseInt(v));

              });
              $('#lblSum').html(s);
          }    


Ok Basically I
will pass a value to
Var s
example var s = '50'

Is there a way to pass a value but it only register when keying in a number into my textbox.
So example if I have values in the textbox it will not read these values only the values I type in.
<input type="text" id="txtquantity1" value="10" />
<input type="text" id="txtquantity2" value="20" />
<input type="text" id="txtquantity3" value="5" />
<input type="text" id="txtquantity4" value="5" />
<input type="text" id="txtquantity5" value="10" />

So if I have a sum of 50 in var s and I type in 5 in id=txtquantity5 it will change the value to 45 but I think the only way this will work if it never loads the values from the textboxes but only the value I type in. Reason is because I am passing the combined value to var  S. So it will not have to add the value just subtract or add the value when I type it in.
Understand I hope.
LVL 9
Seven priceFull StackAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

darren-w-Commented:
Hi,

Could you rephrase your question please, not quite sure what your asking, this is what I have:

<!DOCTYPE html>
<html>
    <head>
        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <script type="text/javascript">           
            $(function() {
                $('input[id^="txtquantity"]').live('keyup', function() {
                    getSum();
                });
            });
            function getSum() {
                var s = 0;
                $('input[id^="txtquantity"]').each(function() {
                    var v = $(this).val();
                    s = s + (isNaN(v) ? 0 : parseInt(v));                
                });
                $('#lblSum').html('<p>'+s+'</p>');
            }
        </script>
    </head>
    <body>
        <button id="show">Show Length of Queue</button>
        <span></span>
        <div></div>
        <input type="text" id="txtquantity1" value="10" />
        <input type="text" id="txtquantity2" value="20" />
        <input type="text" id="txtquantity3" value="5" />
        <input type="text" id="txtquantity4" value="5" />
        <input type="text" id="txtquantity5" value="10" />
        <div id ="lblSum"></div>
    </body>
</html>

Open in new window


Do you want to start with a default value and subtract it from 50?

Darren
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Seven priceFull StackAuthor Commented:
tks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.