Jquery or Ajax

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
jauson
Forum Contributor
Posts: 111
Joined: Wed Oct 05, 2011 12:59 am

Jquery or Ajax

Post 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:
Gopesh
Forum Contributor
Posts: 143
Joined: Fri Dec 24, 2010 12:48 am
Location: India

Re: Jquery or Ajax

Post 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.
jauson
Forum Contributor
Posts: 111
Joined: Wed Oct 05, 2011 12:59 am

Re: Jquery or Ajax

Post 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);


});
});
jauson
Forum Contributor
Posts: 111
Joined: Wed Oct 05, 2011 12:59 am

Re: Jquery or Ajax

Post by jauson »

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

Re: Jquery or Ajax

Post 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
jauson
Forum Contributor
Posts: 111
Joined: Wed Oct 05, 2011 12:59 am

Re: Jquery or Ajax

Post by jauson »

thank you alot!!!!
Post Reply