2011-08-11

Jquery : Count Your Profit


This image taken from City Hunter, a new cinema from Korea. The story taken from Manga Create by Tsukasa Hojo. In my country, City Hunter listed as one of many porn manga. And we are banned to see this manga. City Hunter (manga) has ended and continue in Angel Heart, which he meet his daughter (not blood related).. ups spoiler..

Let's play with simple before we using jquery for advance purpose.
I have this form for read my item sales and if the profit I type is like I wanted, then I will submit

Okay.. This script related to basic math, which describe in hitung (function). Hitung or we as Calculate are function to multiple input buy and profit. The result show in another 2 input below it.

To make sure another input not able to change, I add readonly.. It mean the input only to show the value that's you can't change?


<br>BUY:
<
input type="text" name="buy"
    
id="buy1"   />
<
br>Profit (%)
<
input type="text" name="prof"
    
id="prof1" /> persen<br>Sale:
<
input   type="text" name="sale"
       
id="sale1" readonly="readonly" />
<
br>Profit
<
input   type="text" name="share"
     
id="share1" readonly="readonly" />
<
script >
$(
document).ready(function(){
$(
"#buy1").keyup(function() {
     
hitung();
});
$(
"#prof1").keyup(function() {
    
hitung();
});
function 
hitung()
{
    $(
"#tulis").html('please wait');
    var 
buy=parseInt($("#buy1").val());
    var 
prof=parseInt($("#prof1").val());
    var 
sub=buy*(prof/100);
    $(
"#sale1").val(sub);
    $(
"#share1").val(sub+buy);    
     
}

}); 
</script>

Sory if the script using Indonesian. Hope you understand

Tidak ada komentar: