function nenkin とfunction shibougoを条件分岐で出力し(単体ではできている)、
その数値結果を function hituyoのtotalという所に代入し合計数値を出したいです。
これまでしたこと
var nenkin var deathincome をvar totalに入れると計算できませんでした。
よろしくおねがいいたします。
javascript
1function hituyo(){ 2 3// 教育費 4var price3 = document.form1.goods3.options[document.form1.goods3.selectedIndex].value; 5 6// 末っ子の年齢 7var price4 = document.form1.goods4.options[document.form1.goods4.selectedIndex].value; 8 9// 子供の数 10var price5 = document.form1.goods5.options[document.form1.goods5.selectedIndex].value; 11 12//貯蓄額 13var price6 = document.form1.goods6.options[document.form1.goods6.selectedIndex].value; 14 15var nenkin = document.myForm.target.value; 16 17var deathincome = document.myForm1.target1.value; 18 19 20// 合計を計算 支出(教育費+死亡後の生活費+葬儀代) - 収入(遺族・厚生年金+児童扶養手当+児童手当+死亡後の収入+貯蓄) 21var total = (parseInt(price3)+((22-parseInt(price4))*2400000)+1500000)-(parseInt(nenkin)+(18-parseInt(price4))*240000+(200-(110000*parseInt(price4))*parseInt(price5))+parseInt(deathincome)+parseInt(price6)); 22document.form1.field_total1.value = total; // 合計を表示 23//--> 24} 25///遺族年金・厚生年金//// 26function nenkin(){ 27///子供の数//// 28 var price5 = document.form1.goods5.options[document.form1.goods5.selectedIndex].value; 29 ///あなたの年齢//// 30 var price7 = document.form1.goods7.options[document.form1.goods7.selectedIndex].value; 31 32 if (parseInt(price5) == 0 && parseInt(price7) == 20){ 33 document.myForm._text.value = "55555"; 34 document.getElementById("target").value = 6370000; 35 }else if(parseInt(price5) == 1 && parseInt(price7) == 20){ 36 document.myForm._text.value = "55555"; 37 document.getElementById("target").value = 19500000; 38 }else if(parseInt(price5) == 2 && parseInt(price7) == 20){ 39 document.myForm._text.value = "55555"; 40 document.getElementById("target").value = 22490000; 41 }else if(parseInt(price5) == 3 && parseInt(price7) == 20){ 42 document.myForm._text.value = "55555"; 43 document.getElementById("target").value = 23400000; 44 }else if(parseInt(price5) == 0 && parseInt(price7) == 30){ 45 document.myForm._text.value = "55555"; 46 document.getElementById("target").value = 7410000; 47 }else if(parseInt(price5) == 1 && parseInt(price7) == 30){ 48 document.myForm._text.value = "55555"; 49 document.getElementById("target").value = 20540000; 50 }else if(parseInt(price5) == 2 && parseInt(price7) == 30){ 51 document.myForm._text.value = "55555"; 52 document.getElementById("target").value = 23530000; 53 }else if(parseInt(price5) == 3 && parseInt(price7) == 30){ 54 document.myForm._text.value = "55555"; 55 document.getElementById("target").value = 34570000; 56 }else if(parseInt(price5) == 0 && parseInt(price7) == 40){ 57 document.myForm._text.value = "55555"; 58 document.getElementById("target").value = 8450000; 59 }else if(parseInt(price5) == 1 && parseInt(price7) == 40){ 60 document.myForm._text.value = "55555"; 61 document.getElementById("target").value = 21190000; 62 }else if(parseInt(price5) == 2 && parseInt(price7) == 40){ 63 document.myForm._text.value = "55555"; 64 document.getElementById("target").value = 24570000; 65 }else if(parseInt(price5) == 3 && parseInt(price7) == 40){ 66 document.myForm._text.value = "55555"; 67 document.getElementById("target").value = 25350000; 68 }else if(parseInt(price5) == 0 && parseInt(price7) == 50){ 69 document.myForm._text.value = "55555"; 70 document.getElementById("target").value = 11700000; 71 }else if(parseInt(price5) == 1 && parseInt(price7) == 50){ 72 document.myForm._text.value = "55555"; 73 document.getElementById("target").value = 24700000; 74 }else if(parseInt(price5) == 2 && parseInt(price7) == 50){ 75 document.myForm._text.value = "55555"; 76 document.getElementById("target").value = 27300000; 77 }else if(parseInt(price5) == 3 && parseInt(price7) == 50){ 78 document.myForm._text.value = "55555"; 79 document.getElementById("target").value = 28600000; 80 }else { 81 document.myForm._text.value = "55555"; 82 document.getElementById("target").value = "選択してください"; 83 } 84 } 85 ///死亡後収入//// 86 function shibougo(){ 87 ///妻の働き方//// 88 var price8 = document.form1.goods8.options[document.form1.goods8.selectedIndex].value; 89 ///あなたの年齢//// 90 var price7 = document.form1.goods7.options[document.form1.goods7.selectedIndex].value; 91 92 if (parseInt(price8) == 0 && parseInt(price7) == 20){ 93 document.myForm1.deathincome.value = "37400000"; 94 document.getElementById("target1").value = 37400000; 95 }else if(parseInt(price8) == 1 && parseInt(price7) == 20){ 96 document.myForm1.deathincome.value = "37400000"; 97 document.getElementById("target1").value = 37400000; 98 }else if(parseInt(price8) == 0 && parseInt(price7) == 30){ 99 document.myForm1.deathincome.value = "37400000"; 100 document.getElementById("target1").value = 37400000; 101 }else if(parseInt(price8) == 1 && parseInt(price7) == 30){ 102 document.myForm1.deathincome.value = "45900000"; 103 document.getElementById("target1").value = 45900000; 104 }else if(parseInt(price8) == 0 && parseInt(price7) == 40){ 105 document.myForm1.deathincome.value = "37400000"; 106 document.getElementById("target1").value = 37400000; 107 }else if(parseInt(price8) == 1 && parseInt(price7) == 40){ 108 document.myForm1.deathincome.value = "49300000"; 109 document.getElementById("target1").value = 49300000; 110 }else if(parseInt(price8) == 0 && parseInt(price7) == 50){ 111 document.myForm1.deathincome.value = "37400000"; 112 document.getElementById("target1").value = 37400000; 113 }else if(parseInt(price8) == 1 && parseInt(price7) == 50){ 114 document.myForm1.deathincome.value = "37400000"; 115 document.getElementById("target1").value = 37400000; 116 }else { 117 document.myForm1.deathincome.value = "55555"; 118 document.getElementById("target1").value = "選択してください"; 119 } 120 }
HIML
1<div class="calculation-wrapper" id="calculation"> 2 <h1>カクホ診断</h1> 3 <p>簡単な質問に答えて、まずは保険の見直し!<br>必要以上に入りすぎていて無駄!、家族を守るために足りない!が一目でわかります。</p> 4</div> 5<div class="sindan"> 6 <form name="myForm"> 7 <input type="text" id="target" name="_text" size="15" value="0"> 8 </form> 9 <form name="myForm1"> 10 <input type="text" id="taeget1" name="deathincome" size="15" value="0"> 11 </form> 12 <div class="you-wrapper"> 13 <div class="container"> 14 <h4 class="sindan-title">家庭に関して</h4> 15 <ul> 16 <li class="q">①あなたの年齢は? 17 <div class="q1"> 18 <form action="#" name="form1"> 19 <select name="goods7" onChange="nenkin()" onChange="shibougo()"> 20 <option value="100">---</option> 21 <option value="20">20代</option> 22 <option value="30">30代</option> 23 <option value="40">40代</option> 24 <option value="50">50代</option> 25 </select> 26 </div> 27 </li> 28 <li class="q">②お子さんの人数は? 29 <div class="q2"> 30 <select name="goods5" onChange="hituyo()" onChange="nenkin()"> 31 <option value="100">---</option> 32 <option value="0">0人</option> 33 <option value="1">1人</option> 34 <option value="2">2人</option> 35 <option value="3">3人以上</option> 36 </select> 37 </div> 38 </li> 39 <li class="q">③お子さん(末っ子)の年齢? 40 <div class="q3"> 41 <select name="goods4" onChange="hituyo()"> 42 <option value="100">---</option> 43 <option value="0">妊娠中</option> 44 <option value="0">0歳</option> 45 <option value="1">1歳</option> 46 <option value="2">2歳</option> 47 //以下省略 48 </select> 49 </div> 50 </li> 51 <li class="q">④家庭の働き方は? 52 <div class="q4"> 53 <select name="goods8" onChange="shibougo()"> 54 <option value="100">---</option> 55 <option value="0">共働き(パート)</option> 56 <option value="0">専業主婦・主夫</option> 57 <option value="1">共働き(正社員)</option> 58 </select> 59 </div> 60 </li> 61 <li class="q">⑤現在の貯蓄額は? 62 <div class="q5"> 63 <select name="goods6" onChange="hituyo()"> 64 <option value="100">---</option> 65 <option value="1000000">〜100万円</option> 66 <option value="3000000">〜300万円</option> 67 <option value="5000000">〜500万円</option> 68 <option value="7000000">〜700万円</option> 69 <option value="9000000">〜900万円</option> 70 <option value="10000000">1000万円以上</option> 71 </select> 72 </div> 73 </li> 74 <li class="q">⑥お子さんの合計教育資金額(教育費シミュレーションで算出した数値の合計) 75 <div class="q6"> 76 <select name="goods3" onChange="hituyo()"> 77 <option value="100">---</option> 78 <option value="5000000">500万円程度</option> 79 <option value="10000000">1000万円程度</option> 80 <option value="15000000">1500万円程度</option> 81 //以下省略 82 </select> 83 </div> 84 </li> </ul> 85 </div> 86 </div> 87 88////結果//// 89<input type="text" name="field_total1" size="15" value="0"> 90
回答1件
あなたの回答
tips
プレビュー