Skip to content

Instantly share code, notes, and snippets.

@dogdoy
Last active July 23, 2016 07:49
Show Gist options
  • Save dogdoy/cd63414d1334a586c8af0d9e3f1ab9f5 to your computer and use it in GitHub Desktop.
Save dogdoy/cd63414d1334a586c8af0d9e3f1ab9f5 to your computer and use it in GitHub Desktop.
ฝากเงิน
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>$title</title>
$styles
</head>
<body>
<h1>คำนวณเงินฝาก</h1>
<p>
<label> ฝากเดือนละ : </label>
<input type="number" id="dep" value="500"> บาท
</p>
<p>
<label>ฝากทั้งสิ้น : </label>
<input type="number" id="year" value="30"> ปี
</p>
<label>ดอกเบี้ยปีละ : </label>
<input type="number" id="det" value="10"> %
</p>
<p>
<input type="button" id="btn" value="คำนวณ" />
</p>
<h3 id="result"></h3>
<p id="allresult"></p>
$scripts
</body>
</html>
function currency(num){
numout = num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
return numout;
}
$(function() {
$('#btn').on('click', function() {
// alert($('#txt').val());
$dep = $('#dep').val();
$year = $('#year').val();
$det = $('#det').val();
var start = 0;
var allresult = "";
for(var i = 1; i <= $year; i++){
//var start = 0;
start = start + ($dep*12);
start = start + ((start*$det)/100);
allresult = allresult + "ปีที่ "+ i+ " ได้ "+ currency(Math.round(start)) + " บาท <br>";
}
$('#result').text("เมื่อครบกำหนด " + $year + " ปี จะได้เงิน " + currency(Math.round(start)) +" บาท");
$('#allresult').html(allresult);
});
});
body {
background: #eee;
font-family: sans-serif;
}
h1{
text-align: center;
}
@media screen and (max-width:640px){
label{
display: inline-block;
width: 35%;
text-align: right;
}
input[type="number"]{
width: 40%;
font-size: 1.5em;
text-align: right;
}
input[type="button"]{
width: 100%;
font-size: 1.5em;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment