Home > Enterprise >  not getting the multiplication in 4th text box
not getting the multiplication in 4th text box

Time:01-20

I want to multiply the three numbers entered in three seprate textbox id is(PaperHeight & PaperWidth & Rate) and then get the product in fourth textbox id is (FinalRate)

I want to get the output when the submit button is clicked

following is my code

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').value;

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

}
<!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="number"  id="FinalRate">
          </div>
        </div>


      </div>
    </div>

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


  </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>

CodePudding user response:

get the element and then set the 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);
  

}
<!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="number"  id="FinalRate">
          </div>
        </div>


      </div>
    </div>

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


  </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>

  •  Tags:  
  • Related