simple addition
Moderator: General Moderators
simple addition
Hi, I want to perform simple addition in jquery.
assumed I have 8 fields, and I want to auto add my field_total.
field1 = 1
field2 = 2
field3 = 3
field4 = 4
field5 = 5
field6 = 6
field7 = 7
field_total = 28
below is my code that i get in any tutorial. how do i add to get this thing done?.
<script>
function newTotal(){
var tot=0;
$('.myAddClass').each(function(){
tot+= 1*$(this).val();
}};
$('#field_total').val( tot);
}
$('.myAddClass').bind('keyup', newTotal);
</script>
cheers!
assumed I have 8 fields, and I want to auto add my field_total.
field1 = 1
field2 = 2
field3 = 3
field4 = 4
field5 = 5
field6 = 6
field7 = 7
field_total = 28
below is my code that i get in any tutorial. how do i add to get this thing done?.
<script>
function newTotal(){
var tot=0;
$('.myAddClass').each(function(){
tot+= 1*$(this).val();
}};
$('#field_total').val( tot);
}
$('.myAddClass').bind('keyup', newTotal);
</script>
cheers!
Re: simple addition
Hi check this http://viralpatel.net/blogs/2009/07/sum ... cript.html. Hope it helps.
Re: simple addition
thanks Gopesh!
Re: simple addition
this is mine.
<script type="text/javascript">
function updatesum() {
document.form.field_total.value = (document.form.tax.value -0) + (document.form.sss.value -0) + (document.form.sss_loan.value -0) + (document.form.philhealth.value -0) + (document.form.pagibig.value -0) + (document.form.pagibig_loan.value -0) + (document.form.medicare.value -0);
}
</script>
<script type="text/javascript">
function updatesum() {
document.form.field_total.value = (document.form.tax.value -0) + (document.form.sss.value -0) + (document.form.sss_loan.value -0) + (document.form.philhealth.value -0) + (document.form.pagibig.value -0) + (document.form.pagibig_loan.value -0) + (document.form.medicare.value -0);
}
</script>
Re: simple addition
Hi,Did u get the result? Are u using pure javascript or jquery? if u don't get the answer pls show ur html code also?
Re: simple addition
Hi Gopesh!
I'm using the code above of your latest post. I think it isn't a jquery. its javascript. cos when i change the value of my one textfield it isnt change immediately on my txt_total.
Regards,
I'm using the code above of your latest post. I think it isn't a jquery. its javascript. cos when i change the value of my one textfield it isnt change immediately on my txt_total.
Regards,
Re: simple addition
Hi,you need to add an onChange event for that. It is better to use jquery ,bcoz it reduces the code and makes it easier.
Re: simple addition
can you give me a quick reference to learn faster in jquery? you have skype?
Re: simple addition
by the way i have onchange for each field i have.
thanks
thanks
Re: simple addition
HI,there are a lot of tutorials available in internet for learning jquery.
Good Links:http://blog.themeforest.net/tutorials/j ... eo-series/
E-book:-jQuery: Novice To Ninja
Without showing ur html code it is not possible to find a solution to ur problem.
Good Links:http://blog.themeforest.net/tutorials/j ... eo-series/
E-book:-jQuery: Novice To Ninja
Without showing ur html code it is not possible to find a solution to ur problem.