Seven price
asked on
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()).len gth < 1) return false;
getSum();
});
});
$(document).ready(function () {
getSum();
});
function getSum() {
var s = 0;
$('input[id^="txtquantity" ]').each(f unction() {
//alert($(this).val());
var v = $(this).val();
s = s + (isNaN(v) ? 0 : parseInt(v));
});
$('#lblSum').html(s);
}
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"
if (String($(this).val()).len
getSum();
});
});
$(document).ready(function
getSum();
});
function getSum() {
var s = 0;
$('input[id^="txtquantity"
//alert($(this).val());
var v = $(this).val();
s = s + (isNaN(v) ? 0 : parseInt(v));
});
$('#lblSum').html(s);
}
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
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
ASKER
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.
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.
Do you have a test URL we can try and what do you mean by pager?
ASKER
Paging you know like a book has pages
ASKER
I've requested that this question be deleted for the following reason:
delete because of rudeness behavior.
delete because of rudeness behavior.
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
I am also getting frustrated posting example after example and not getting anywhere
If you need to show a URL, you can find my email in my profile. Have a good evening
ASKER
ok
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
this looks like it let me put it to my code. Thanks for being patience also.
No problem
ASKER
worked out, Thanks again. I like to get into more jquery. any tutorial sites you recommend
Top 5 links here
https://www.google.com/search?q=best+jquery+tutorial
Also get to know and use jsfiddle - it is so great
https://www.google.com/search?q=best+jquery+tutorial
Also get to know and use jsfiddle - it is so great
ASKER
cool thanks
ASKER
<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.