Home > Software engineering >  Not getting addition of all 4th column in total rate
Not getting addition of all 4th column in total rate

Time:02-02

I have created a Rate Calculator for wall hanging

where we have to enter dimensions of 3 entities (Picture,Mount ,Frame) that are

width

height

rate

and 4 column is calculation of 3 dimention

Then I have created total rate where the addition of all 4th column is calculated

function btnclick() {
  var PictureHeight = document.getElementById('PictureHeight').value;
  var PictureWidth = document.getElementById('PictureWidth').value;
  var Rate = document.getElementById('Rate').value;
  var FinalRate = document.getElementById('FinalRate');

  FinalRate.value = parseInt(PictureHeight) * parseInt(PictureWidth) * parseInt(Rate);


  var MountHeight = document.getElementById('MountHeight').value;
  var MountWidth = document.getElementById('MountWidth').value;
  var MountRate = document.getElementById('MountRate').value;
  var MFinalRate = document.getElementById('MFinalRate');

  MFinalRate.value = parseInt(2 * MountHeight)   parseInt(2 * MountWidth) * parseInt(MountRate);

  var FrameHeight = document.getElementById('FrameHeight').value;
  var FrameWidth = document.getElementById('FrameWidth').value;
  var FrameRate = document.getElementById('FrameRate').value;
  var FrFinalRate = document.getElementById('FrFinalRate');

  FrFinalRate.value = parseInt(2 * FrameHeight)   parseInt(2 * FrameWidth) * parseInt(FrameRate);


  var TFinalRate = document.getElementById('TFinalRate');

  TFinalRate.value = parseInt(FinalRate)   parseInt(MFinalRate)   parseInt(FrFinalRate);


}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
  <link rel="stylesheet" href="style.css">
  <title>Calculator</title>
</head>

<body>
  <center>

    <h1>Rate Calculator</h1>

    Enter the Picture dimention and Rate<br/>

    <div >
      <div >
        <div >

          <div >
            <label >Width</label>
            <input type="number"  id="PictureWidth">
          </div>

        </div>

        <div >
          <div >
            <label >Height</label>
            <input type="number"  id="PictureHeight">
          </div>
        </div>

        <div >
          <div >
            <label >Rate</label>
            <input type="number"  id="Rate">
          </div>
        </div>
        <br>

        <div >
          <div >
            <label >&#8377;</label>
            <input type="text"  id="FinalRate">
          </div>
        </div>






      </div>
    </div>




    Enter the Mount dimention and Rate<br/>

    <div >
      <div >
        <div >

          <div >
            <label >Width</label>
            <input type="number"  id="MountWidth">
          </div>

        </div>

        <div >
          <div >
            <label >Height</label>
            <input type="number"  id="MountHeight">
          </div>
        </div>

        <div >
          <div >
            <label >Rate</label>
            <input type="number"  id="MountRate">
          </div>
        </div>
        <br>

        <div >
          <div >
            <label >&#8377;</label>
            <input type="text"  id="MFinalRate">
          </div>
        </div>






      </div>
    </div>


    Enter the Frame dimention and Rate<br/>

    <div >
      <div >
        <div >

          <div >
            <label >Width</label>
            <input type="number"  id="FrameWidth">
          </div>

        </div>

        <div >
          <div >
            <label >Height</label>
            <input type="number"  id="FrameHeight">
          </div>
        </div>

        <div >
          <div >
            <label >Rate</label>
            <input type="number"  id="FrameRate">
          </div>
        </div>
        <br>

        <div >
          <div >
            <label >&#8377;</label>
            <input type="text"  id="FrFinalRate">
          </div>
        </div>





      </div>
    </div>






    Total Rate is<br/>

    <div >
      <div >
        <div >


        </div>

        <div >

        </div>
        <label >&#8377;</label>
        <input type="text"  id="TFinalRate">
        <div >

        </div>
        <br>

        <div >

        </div>


        <button type="button"  onclick="btnclick()">Submit</button>




      </div>
    </div>










  </center>




  <script src="script.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg OMhuP IlRH9sENBO0LRn5q 8nbTov4 1p" crossorigin="anonymous">
  </script>
</body>

</html>

but when u click on submit it shows NAN in total Rate

CodePudding user response:

there is only one error is that you haven't take the value of TFinalRate.value = parseInt(FinalRate.value) parseInt(MFinalRate.value) parseInt(FrFinalRate.value);

You should use FinalRate.value, FinalRate.value and MFinalRate.value

 function btnclick() {
  var PictureHeight = document.getElementById('PictureHeight').value;
  var PictureWidth = document.getElementById('PictureWidth').value;
  var Rate = document.getElementById('Rate').value;
  var FinalRate = document.getElementById('FinalRate');

  FinalRate.value = parseInt(PictureHeight) * parseInt(PictureWidth) * parseInt(Rate);


  var MountHeight = document.getElementById('MountHeight').value;
  var MountWidth = document.getElementById('MountWidth').value;
  var MountRate = document.getElementById('MountRate').value;
  var MFinalRate = document.getElementById('MFinalRate');

  MFinalRate.value = parseInt(2 * MountHeight)   parseInt(2 * MountWidth) * parseInt(MountRate);

  var FrameHeight = document.getElementById('FrameHeight').value;
  var FrameWidth = document.getElementById('FrameWidth').value;
  var FrameRate = document.getElementById('FrameRate').value;
  var FrFinalRate = document.getElementById('FrFinalRate');

  FrFinalRate.value = parseInt(2 * FrameHeight)   parseInt(2 * FrameWidth) * parseInt(FrameRate);


  var TFinalRate = document.getElementById('TFinalRate');

  TFinalRate.value = parseInt(FinalRate.value)   parseInt(MFinalRate.value)   parseInt(FrFinalRate.value);


}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
  <link rel="stylesheet" href="style.css">
  <title>Calculator</title>
</head>

<body>
  <center>

    <h1>Rate Calculator</h1>

    Enter the Picture dimention and Rate<br/>

    <div >
      <div >
        <div >

          <div >
            <label >Width</label>
            <input type="number"  id="PictureWidth">
          </div>

        </div>

        <div >
          <div >
            <label >Height</label>
            <input type="number"  id="PictureHeight">
          </div>
        </div>

        <div >
          <div >
            <label >Rate</label>
            <input type="number"  id="Rate">
          </div>
        </div>
        <br>

        <div >
          <div >
            <label >&#8377;</label>
            <input type="text"  id="FinalRate">
          </div>
        </div>






      </div>
    </div>




    Enter the Mount dimention and Rate<br/>

    <div >
      <div >
        <div >

          <div >
            <label >Width</label>
            <input type="number"  id="MountWidth">
          </div>

        </div>

        <div >
          <div >
            <label >Height</label>
            <input type="number"  id="MountHeight">
          </div>
        </div>

        <div >
          <div >
            <label >Rate</label>
            <input type="number"  id="MountRate">
          </div>
        </div>
        <br>

        <div >
          <div >
            <label >&#8377;</label>
            <input type="text"  id="MFinalRate">
          </div>
        </div>






      </div>
    </div>


    Enter the Frame dimention and Rate<br/>

    <div >
      <div >
        <div >

          <div >
            <label >Width</label>
            <input type="number"  id="FrameWidth">
          </div>

        </div>

        <div >
          <div >
            <label >Height</label>
            <input type="number"  id="FrameHeight">
          </div>
        </div>

        <div >
          <div >
            <label >Rate</label>
            <input type="number"  id="FrameRate">
          </div>
        </div>
        <br>

        <div >
          <div >
            <label >&#8377;</label>
            <input type="text"  id="FrFinalRate">
          </div>
        </div>





      </div>
    </div>






    Total Rate is<br/>

    <div >
      <div >
        <div >


        </div>

        <div >

        </div>
        <label >&#8377;</label>
        <input type="text"  id="TFinalRate">
        <div >

        </div>
        <br>

        <div >

        </div>


        <button type="button"  onclick="btnclick()">Submit</button>




      </div>
    </div>










  </center>




  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg OMhuP IlRH9sENBO0LRn5q 8nbTov4 1p" crossorigin="anonymous">
</script>

</body>

</html>

  •  Tags:  
  • Related