JavaScript and client side scripting.
Moderator: General Moderators
jauson
Forum Contributor
Posts: 111 Joined: Wed Oct 05, 2011 12:59 am
Post
by jauson » Wed Feb 08, 2012 9:18 pm
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
Gopesh
Forum Contributor
Posts: 143 Joined: Fri Dec 24, 2010 12:48 am
Location: India
Post
by Gopesh » Wed Feb 08, 2012 10:21 pm
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.
jauson
Forum Contributor
Posts: 111 Joined: Wed Oct 05, 2011 12:59 am
Post
by jauson » Wed Feb 08, 2012 11:21 pm
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);
});
});
jauson
Forum Contributor
Posts: 111 Joined: Wed Oct 05, 2011 12:59 am
Post
by jauson » Wed Feb 08, 2012 11:42 pm
is it correct the script type?
<script type="text/javascript" src="js/jquery-1.6.4.js"></script>
<script>
Gopesh
Forum Contributor
Posts: 143 Joined: Fri Dec 24, 2010 12:48 am
Location: India
Post
by Gopesh » Wed Feb 08, 2012 11:54 pm
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
jauson
Forum Contributor
Posts: 111 Joined: Wed Oct 05, 2011 12:59 am
Post
by jauson » Thu Feb 09, 2012 2:47 am
thank you alot!!!!