1

select によって選択された 3 つの異なる貯蓄計画のいずれかを計算するために変更する必要がある、基本的な JavaScript 金利計算機があります。

基本的なコードは正常に動作しています:

function CalculateNonComp() {
if (!parseFloat(document.noncomp.noncomp_principal.value)) {
    document.noncomp.noncomp_principal.value = 0;
};
if (!parseFloat(document.noncomp.noncomp_interest.value)) {
    document.noncomp.noncomp_interest.value = 1.4;
};
if (!parseFloat(document.noncomp.noncomp_length.value)) {
    document.noncomp.noncomp_length.value = 30;
};
var Principal = parseFloat(document.noncomp.noncomp_principal.value);
var DailyInterest = parseFloat(document.noncomp.noncomp_interest.value) / 1;
DailyInterest = DailyInterest / 100;
var Days = parseInt(document.noncomp.noncomp_length.value) * 1;
var Result = Principal * (1 + DailyInterest * Days);
document.getElementById('noncomp_result').innerHTML = Result.toFixed(2);
}

私の問題は、if....else if....elseステートメントを実装してselectによって選択された正しい貯蓄計画を計算しようとすると始まります。

私は次のことを試しました:

function CalculateNonComp() {
if (document.noncomp.plan.value = "1");
if (!parseFloat(document.noncomp.noncomp_principal.value)) {
    document.noncomp.noncomp_principal.value = 0;
};
if (!parseFloat(document.noncomp.noncomp_interest.value)) {
    document.noncomp.noncomp_interest.value = 1.4;
};
if (!parseFloat(document.noncomp.noncomp_length.value)) {
    document.noncomp.noncomp_length.value = 30;
};


var Principal = parseFloat(document.noncomp.noncomp_principal.value);
var DailyInterest = parseFloat(document.noncomp.noncomp_interest.value) / 1;
DailyInterest = DailyInterest / 100;


var Days = parseInt(document.noncomp.noncomp_length.value) * 1;

var Result = Principal * (1 + DailyInterest * Days);

document.getElementById('noncomp_result').innerHTML = Result.toFixed(2);

else if (document.noncomp.plan.value = "2");


if (!parseFloat(document.noncomp.noncomp_principal.value)) {
    document.noncomp.noncomp_principal.value = 0;
};
if (!parseFloat(document.noncomp.noncomp_interest.value)) {
    document.noncomp.noncomp_interest.value = 1.6;
};
if (!parseFloat(document.noncomp.noncomp_length.value)) {
    document.noncomp.noncomp_length.value = 60;
};


var Principal = parseFloat(document.noncomp.noncomp_principal.value);
var DailyInterest = parseFloat(document.noncomp.noncomp_interest.value) / 1;
DailyInterest = DailyInterest / 100;


var Days = parseInt(document.noncomp.noncomp_length.value) * 1;

var Result = Principal * (1 + DailyInterest * Days);

document.getElementById('noncomp_result').innerHTML = Result.toFixed(2);

else(document.noncomp.plan.value = "3");


if (!parseFloat(document.noncomp.noncomp_principal.value)) {
    document.noncomp.noncomp_principal.value = 0;
};
if (!parseFloat(document.noncomp.noncomp_interest.value)) {
    document.noncomp.noncomp_interest.value = 1.8;
};
if (!parseFloat(document.noncomp.noncomp_length.value)) {
    document.noncomp.noncomp_length.value = 90;
};


var Principal = parseFloat(document.noncomp.noncomp_principal.value);
var DailyInterest = parseFloat(document.noncomp.noncomp_interest.value) / 1;
DailyInterest = DailyInterest / 100;


var Days = parseInt(document.noncomp.noncomp_length.value) * 1;

var Result = Principal * (1 + DailyInterest * Days);

document.getElementById('noncomp_result').innerHTML = Result.toFixed(2);

}

ヒントや助けをありがとう!

4

4 に答える 4

-2

Javaスクリプトを使用して、フォームとテキストボックスの検証のすべての入力検証で単利を計算し、cssも適用しようとしています

         <html>

        <head>
       <title>SIMPLE INTEREST CALCULATION</title>

       <link type="text/css"  href="style.css"  rel="stylesheet ">

        <script type="text/javascript" src="style.js">  

        </script>

      </head>

       <body>

     <form name="frm">

    <center>

    <h1>....Simple Interest Calculation....</h1>

     <div id="div">

    <table id="t1">

     <caption> </caption>

     <tr> 
     <td>Amount Rs/-
     </td>

     <td> 

     <input type="text" name="amount" id="amount" value="" class="input" min="0"  onkeyup="AllowNumber()"/>
      </td>
     </tr>

      <tr>
      <td>Rate Rs/-
    </td>

       <td><input type="text" name="rate" id="per" value="" min="0" max="3"     class="input" />
     </td>
    </tr>

   <tr>
   <td>Time peroid:</td>
   <td>
    <input type="number" name="time" value="" id="time" min="0" class="input"/>

   <select id="peroid" class="choice">

  <option>Choose</option>

  <option value="year">Year</option>

  <option value="month">Month</option>

  <option value="weeks">Weeks</option>

   <option value="days">Days</option>

   </select>

   </td>

   </tr>

   <tr>

   <td>
Total Interest:
   </td>

    <td>
    <input type="text" id="interest" value="" name="interest" class="input" readonly/>
  </td>
  </tr>

  <tr><td>TotalAmount:</td>
    <td><input type="text" id="total" name="total" value="" class="input" readonly/></td></tr>

    <tr>
   <td><input type="button" name="cal" id="cal" value="Calculate" class="cal" onclick="cali()"/>
   </td>

     <td><input type="reset" name="clear" id="cal" value="Clear" class="cal"/>    </td></tr>
    </table>
   </center>
    </div>
  </form>
  </body>
   </html>


   **CSS Code**//style.css

  .input
   {
    font-weight:bold;
    width:260px;
    height:32px;
    font-size:1em;
    text-align: right
   }

    #amount
    {
   border-radius: 40px;
    border:2px solid teal;
    }
    #per
    {
    border-radius: 40px;
    border:2px solid teal;
     }

    #time
   {
     border-radius: 40px;
     border:2px solid teal;
    width:130px;
    height:30px;
     }

     #interest
    {
     border-radius: 40px;
     border:2px solid teal;
    }
     #total
    {
    border-radius: 40px;
    border:2px solid teal;
   }
   .cal
    {
    font-weight:bold;
   width:250px;
   height:40px;
   font-size:1em;
    border-radius: 50px;
   border:2px solid black;
   }
   #t1
    {
     color:teal;
    font-size:2em;
    border-radius: 40px;
    font-weight:bold;

    font-family:Gabriola;
    }

    select
   {
   border-radius: 40px;
   border:2px solid teal;
   width:130px;
   height:35px;
   font-size:1em;
   }

   #div
   {
    background-color: lightgrey;
   width: 600px;
    padding: 20px;
    border: 25px solid green;
     margin: 20px;
    border-style: inset;
    border-radius: 50px;
    box-shadow: 10px 10px 5px red;
    }
    h1
   {
   color:purple;
   hypens:auto;
    text-shadow: 10px 10px 10px black;
  font-weight:bold;
  font-variant: small-caps;
   font-size:3em;
  }
  #d1
 {
    background-color: lightgrey;
   width: 850px;
   padding: 25px;
    border: 25px solid navy;
    margin:60px;
    margn-left:5px;
   }

  #cal
  {
  background-color:teal;
  width:280px;!important
  height:33px;!important
  }

  **JavaScript Code**//style.js

    //Empty text box validation

 function cali()
 {
   var p,r,n,y,m,w,d;
  if(document.frm.amount.value == "" )
   {
   alert("PLEASE ENTER PRINCIPLE AMOUNT");
    document.frm.amount.alert();
   }
   else if(document.frm.rate.value=="")
  {
   alert("ENTER RATE OF INTEREST");
   document.frm.rate.blur();
   }

   if(parseFloat(per.value)>100)//text box allow only range of within 100
   {
    alert("Please Enter The Interest Rate Less Then 100");
     per[i].focus();
    return (false);
  }

   if(parseFloat(per.value)<0)//text box allow only range of Greater Than Zero
   {
     alert("Please Enter The Interest Rate Greater then 0");
     per[i].focus();
     return (false);
   }

     if(!document.getElementById("per").value.match(/^[0-9]*\.?[0-9]*$/))//text box allow only numbers and allow only one dot
    {
  alert("Enter Correct Interest Rate");
   return (false);
   }
   else if(document.frm.time.value=="")
   {
    alert("ENTER NUMBER OF TIME PERIOD");
    document.frm.time.prompt();
   }
   else
  {
  p=parseInt(document.frm.amount.value);

  r=parseFloat(document.frm.rate.value);

  n=parseInt(document.frm.time.value);

   peroid=document.getElementById("peroid").value;

   if(peroid=="year")// per year calculation
   {
    y=(p*r*n)/100;
    document.frm.interest.value="Rs :" +Math.ceil(y);
  }

   else if(peroid=="month")//per month calculation
  {
   m=(p*r*(n/12))/100;
  document.frm.interest.value="Rs :" +Math.ceil(m);
  }

   else if(peroid=="weeks")//per week calculation
    {
  var w=(p*r*(n/52))/100;
   document.frm.interest.value="Rs :" + Math.ceil(w);
   }


    else if(peroid=="days")//per days calculation
   {
   d=(p*r*(n/365))/100;
   document.frm.interest.value="Rs :" + Math.ceil(d);
  }

    document.frm.total.value="Rs:"+Math.ceil((p+m)||(p+y)||(p+w)||(p+d));
   }
   }

   //Text Box Allow Only The Numeric Values not allow single dot or char

   function AllowNumber(){
   if (!frm.amount.value.match(/[0-9]+$/) && frm.amount.value !="")
    {
       frm.amount.value="";
     frm.amount.focus();
    alert("Please Enter only Numers In This Field");
    }
    }
于 2015-01-16T06:03:30.100 に答える