★消費税比較 [ JSサンプル ]
URL:http://web-parts.itland.ezic.info/sample-parts/cal-con-tax/
[html title=’HTML’]
< !DOCTYPE html>
消費税比較 [ jsサンプル ]
ウェブパーツの置き場 > 消費税比較 [ jsサンプル ]
ソースファイル [ウェブコーディング研究ログ]
主な利用機能
- 金額を入力して本体価格・消費税価格を計算する
[/html]
[JavaScript title=’JavaScript’]
//————————————————
// 本体価格:
//————————————————
function cal1(){
//価格配列
var Kakaku = {};
// 入力値チェック
var inputValue = document.sample_form.sample_box1.value;
if(!isNumber(inputValue)){
return false;
}else{
Kakaku[‘hontai’] = inputValue;
}
// 各種価格計算
Kakaku[‘hontai’] = Kakaku[‘hontai’];
Kakaku[‘5%’] = Math.round(Kakaku[‘hontai’] * 1.05);
Kakaku[‘8%’] = Math.round(Kakaku[‘hontai’] * 1.08);
Kakaku[‘10%’] = Math.round(Kakaku[‘hontai’] * 1.10);
Kakaku[‘5%to8%’] = Kakaku[‘8%’] – Kakaku[‘5%’];
Kakaku[‘8%to10%’] = Kakaku[‘10%’] – Kakaku[‘8%’];
// 結果を出力
document.sample_form.sample_box1.value = Kakaku[‘hontai’];
document.sample_form.sample_box2.value = Kakaku[‘5%’];
document.sample_form.sample_box3.value = Kakaku[‘8%’];
document.sample_form.sample_box4.value = Kakaku[‘10%’];
document.getElementById(‘sample_id1’).innerHTML = Math.round(Kakaku[‘5%to8%’]) + ‘ 円’;
document.getElementById(‘sample_id2’).innerHTML = Math.round(Kakaku[‘8%to10%’]) + ‘ 円’;
}
//————————————————
// 消費税5%価格:
//————————————————
function cal2(){
//価格配列
var Kakaku = {};
// 入力値
var inputValue = document.sample_form.sample_box2.value;
if(!isNumber(inputValue)){
return false;
}else{
Kakaku[‘5%’] = inputValue;
}
// 各種価格計算
Kakaku[‘hontai’] = Math.round(Kakaku[‘5%’] / 1.05);
Kakaku[‘5%’] = Math.round(Kakaku[‘hontai’] * 1.05);
Kakaku[‘8%’] = Math.round(Kakaku[‘hontai’] * 1.08);
Kakaku[‘10%’] = Math.round(Kakaku[‘hontai’] * 1.10);
Kakaku[‘5%to8%’] = Kakaku[‘8%’] – Kakaku[‘5%’];
Kakaku[‘8%to10%’] = Kakaku[‘10%’] – Kakaku[‘8%’];
// 結果を出力
document.sample_form.sample_box1.value = Kakaku[‘hontai’];
document.sample_form.sample_box2.value = Kakaku[‘5%’];
document.sample_form.sample_box3.value = Kakaku[‘8%’];
document.sample_form.sample_box4.value = Kakaku[‘10%’];
document.getElementById(‘sample_id1’).innerHTML = Math.round(Kakaku[‘5%to8%’]) + ‘ 円’;
document.getElementById(‘sample_id2’).innerHTML = Math.round(Kakaku[‘8%to10%’]) + ‘ 円’;
}
//————————————————
// 消費税8%価格:
//————————————————
function cal3(){
//価格配列
var Kakaku = {};
// 入力値
var inputValue = document.sample_form.sample_box3.value;
if(!isNumber(inputValue)){
return false;
}else{
Kakaku[‘8%’] = inputValue;
}
// 各種価格計算
Kakaku[‘hontai’] = Math.round(Kakaku[‘8%’] / 1.08);
Kakaku[‘5%’] = Math.round(Kakaku[‘hontai’] * 1.05);
Kakaku[‘8%’] = Math.round(Kakaku[‘hontai’] * 1.08);
Kakaku[‘10%’] = Math.round(Kakaku[‘hontai’] * 1.10);
Kakaku[‘5%to8%’] = Kakaku[‘8%’] – Kakaku[‘5%’];
Kakaku[‘8%to10%’] = Kakaku[‘10%’] – Kakaku[‘8%’];
// 結果を出力
document.sample_form.sample_box1.value = Kakaku[‘hontai’];
document.sample_form.sample_box2.value = Kakaku[‘5%’];
document.sample_form.sample_box3.value = Kakaku[‘8%’];
document.sample_form.sample_box4.value = Kakaku[‘10%’];
document.getElementById(‘sample_id1’).innerHTML = Math.round(Kakaku[‘5%to8%’]) + ‘ 円’;
document.getElementById(‘sample_id2’).innerHTML = Math.round(Kakaku[‘8%to10%’]) + ‘ 円’;
}
//————————————————
// 消費税10%価格:
//————————————————
function cal4(){
//価格配列
var Kakaku = {};
// 入力値
var inputValue = document.sample_form.sample_box4.value;
if(!isNumber(inputValue)){
return false;
}else{
Kakaku[‘10%’] = inputValue;
}
// 各種価格計算
Kakaku[‘hontai’] = Math.round(Kakaku[‘10%’] / 1.10);
Kakaku[‘5%’] = Math.round(Kakaku[‘hontai’] * 1.05);
Kakaku[‘8%’] = Math.round(Kakaku[‘hontai’] * 1.08);
Kakaku[‘10%’] = Math.round(Kakaku[‘hontai’] * 1.10);
Kakaku[‘5%to8%’] = Kakaku[‘8%’] – Kakaku[‘5%’];
Kakaku[‘8%to10%’] = Kakaku[‘10%’] – Kakaku[‘8%’];
// 結果を出力
document.sample_form.sample_box1.value = Kakaku[‘hontai’];
document.sample_form.sample_box2.value = Kakaku[‘5%’];
document.sample_form.sample_box3.value = Kakaku[‘8%’];
document.sample_form.sample_box4.value = Kakaku[‘10%’];
document.getElementById(‘sample_id1’).innerHTML = Math.round(Kakaku[‘5%to8%’]) + ‘ 円’;
document.getElementById(‘sample_id2’).innerHTML = Math.round(Kakaku[‘8%to10%’]) + ‘ 円’;
}
//————————————————
// 変数の数値チェック
//————————————————
function isNumber(str){
if(str.match(/[^0-9]/g)){
return false;
}else{
return true;
}
}
[/JavaScript]
[css title=’StyleSheet’]
@charset “utf8”;
/************************************************/
body{
background-color: #fff;
margin: 0px 0px 0px 20px;
font-family: Arial, “MS ゴシック”, Osaka;
/*background-image: url(“../img/sample.png”);*/
}
#containerA{
float: center;
width: 800px;
height: 200px;
/*vertical-align: middle;*/
}
#containerB{
float: left;
width: 150px;
height: 25px;
vertical-align: middle;
}
#containerC{
float: none;
width: 400px;
height: 25px;
vertical-align: middle;
}
input { width: 75px; }
/************************************************/
#sample_id1{
font-weight: bold;
}
#sample_id2{
font-weight: bold;
}
[/css]
コメント
[…] ★消費税比較 [ jsサンプル ] ※ソースサンプル:消費税比較 [ JavaScript ] | ウェブコーディング研究ログ […]