return add on value

My jquery function below does not work for me. I want this to read my value for
   var s = 0; for example if I have
   var s = 10;
then I want to return 10 and then start adding once i enter a value.
so if I enter a value in the text box as 2 then it will add the 10 plus 2 in realtime to 12
I just do not want this to add all the values in the text box only adding with var s will be.
The reason for this I do not have one big long page with all the textboxes because I am using a pager.
I can get the total value of all the textboxes and pass it to Vars and then if I type a value it will add on to this.


$(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() {
                  //alert($(this).val());
                 var v = $(this).val();
                 s = s + (isNaN(v) ? 0 : parseInt(v));
           });
              $('#lblSum').html(s);
          }
LVL 9
Seven priceFull StackAsked:
Who is Participating?
 
Michel PlungjanIT ExpertCommented:
Is This what you mean?

http://jsfiddle.net/mplungjan/Uvsrp/

I can easily change that to initially show whatever is in the total variable (from server)
0
 
Seven priceFull StackAuthor Commented:
SUM : <label id=lblSum></label><br>
<input type="text" id="txtquantity1" value="0" />
<input type="text" id="txtquantity2" value="3" />
<input type="text" id="txtquantity3" value="0" />
<input type="text" id="txtquantity4" value="0" />
<input type="text" id="txtquantity5" value="0" />

another example if 3 is the value when page is loading, I do not want the 3 to add on I want it add the value if I type the value in.  Is that possible.
0
 
Michel PlungjanIT ExpertCommented:
You are not making yourself very clear which is why we keep seeing this question over and over and over and over....

Please describe is as the user enters your page

1) user enters page and sees x
2) user starts typing and after z strokes he sees y
.
.
.

Why do you have two onloads/ready
Why do you have a function outside the onload - I have shown you code that worked - but this is not that code
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Seven priceFull StackAuthor Commented:
Ok because I am very frustrated.

It works but not with a pager. I cannot return the entire value.

var s must equal only the value I type in from the quantity. I can pass the total value from the page to var s onload and save it but I do not need to return all the values in the quantity field id on load.
0
 
Michel PlungjanIT ExpertCommented:
Do you have a test URL we can try and what do you mean by pager?
0
 
Seven priceFull StackAuthor Commented:
Paging you know like a book has pages
0
 
Seven priceFull StackAuthor Commented:
I've requested that this question be deleted for the following reason:

delete because of rudeness behavior.
0
 
Michel PlungjanIT ExpertCommented:
Sorry if it sounded rude. It was just a bit of fun to get you to not be so frustrated. We will get there if you explain or show a page we can test for you

I am also getting frustrated posting example after example and not getting anywhere
0
 
Michel PlungjanIT ExpertCommented:
If you need to show a URL, you can find my email in my profile. Have a good evening
0
 
Seven priceFull StackAuthor Commented:
ok
0
 
Seven priceFull StackAuthor Commented:
sorry I do not have a url and I get what you are saying x = y

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.
0
 
Seven priceFull StackAuthor Commented:
this looks like it let me put it to my code. Thanks for being patience also.
0
 
Michel PlungjanIT ExpertCommented:
No problem
0
 
Seven priceFull StackAuthor Commented:
worked out, Thanks again. I like to get into more jquery. any tutorial sites you recommend
0
 
Michel PlungjanIT ExpertCommented:
Top 5 links here

https://www.google.com/search?q=best+jquery+tutorial

Also get to know and use jsfiddle - it is so great
0
 
Seven priceFull StackAuthor Commented:
cool thanks
0
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.

All Courses

From novice to tech pro — start learning today.