Page 1 of 1
simple addition
Posted: Mon Feb 13, 2012 7:09 pm
by jauson
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!
Re: simple addition
Posted: Mon Feb 13, 2012 10:55 pm
by Gopesh
Re: simple addition
Posted: Tue Feb 14, 2012 12:54 am
by jauson
thanks Gopesh!
Re: simple addition
Posted: Tue Feb 14, 2012 12:56 am
by jauson
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>
Re: simple addition
Posted: Tue Feb 14, 2012 4:02 am
by Gopesh
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
Posted: Tue Feb 14, 2012 6:15 pm
by jauson
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,
Re: simple addition
Posted: Tue Feb 14, 2012 10:31 pm
by Gopesh
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
Posted: Wed Feb 15, 2012 2:32 am
by jauson
can you give me a quick reference to learn faster in jquery? you have skype?
Re: simple addition
Posted: Wed Feb 15, 2012 2:45 am
by jauson
by the way i have onchange for each field i have.
thanks
Re: simple addition
Posted: Wed Feb 15, 2012 3:07 am
by Gopesh
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.