Page 1 of 1

Jquery or Ajax

Posted: Wed Feb 08, 2012 9:18 pm
by jauson
Hi everyone,

does everyone here knows how to automatically calculate fields?

assumed i have

field_salary
field_payout
field_perday

when i input 5000 in field_salary,
field_payout will automatically devided field_salary by 2 and field_perday will automatically devided field_perday by 13/days.


for example


field_S 5000
Field_P 2500
Field_D 198.00


Many thanks :banghead:

Re: Jquery or Ajax

Posted: Wed Feb 08, 2012 10:21 pm
by Gopesh
Hi,You can use jquery for this.
check this http://jsfiddle.net/cyW8v/3/.
The calculations are not correct ,do the right calculations.Hope it helps.

Re: Jquery or Ajax

Posted: Wed Feb 08, 2012 11:21 pm
by jauson
Hi Gopesh!

your really amazing!

here's my code./

$(document).ready(function() {
$('#salary').keyup(function() {
var sal=$(this).val();
var payout=sal/2;
var field_perday=payout/13;


field_perday= Math.floor(field_perday* 100) / 100;



$('#payout').val(payout);
$('#perday').val(field_perday);


});
});

Re: Jquery or Ajax

Posted: Wed Feb 08, 2012 11:42 pm
by jauson
is it correct the script type?

<script type="text/javascript" src="js/jquery-1.6.4.js"></script>
<script>

Re: Jquery or Ajax

Posted: Wed Feb 08, 2012 11:54 pm
by Gopesh
Use like this.

Code: Select all

<script type="text/javascript" src="js/jquery-1.6.4.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#salary').keyup(function() {
var sal=$(this).val();
var payout=sal/2;
var field_perday=payout/13;


field_perday= Math.floor(field_perday* 100) / 100;



$('#payout').val(payout);
$('#perday').val(field_perday);


});
});
</script>

DEbugging Tips:
Press ctrl +shift +j for displaying jquery or javascript errors in Firefox

Re: Jquery or Ajax

Posted: Thu Feb 09, 2012 2:47 am
by jauson
thank you alot!!!!