I would like to display the results calculated by JavaScript in HTML.

Asked 4 months ago, Updated 4 months ago, 10 views

symptoms
I want to calculate the appropriate weight (calculated by the square of height (m) x 22) in JavaScript, but nothing happens when I enter height (m) entered from index.html.An error appears in the console.

Below is the actual console error
console Error

Expectations
After entering height (m) in the input form, the appropriate weight is displayed.

Reproduction Steps
Execute the following code.

index.html

<!DOCTYPE html>
<html>
<head>
    <metacharset="UTF-8">
    <title> Find the right weight by the square of height (m) x 22</title>
</head>
<body>
    Height (m): <input type="number" step="0.01"><br>
    <input type="submit" value="send" id="calculation"> 
    Proper Weight (kg): <pid="result">/p>

    <script type="text/javascript" src="calculation.js"></script>
</body>
</html>

calculation.js

'use strict';

var calculation = document.getElementById('calculation');
calculation.addEventListener('submit',(e)=>{

  vareleHeight= document.getElementById("height");

  function calc(){
  varheight=parseFloat(eleHeight.value);

  var heightSquared=Math.power(height,2);
  var approveWeight=heightSquared*22;
  };

  console.log (approachWeight);
  var result = approveWeight;
  result.innerHTML = "approduceWeight";
});

Supplementary
The height you enter is not centimeters, but meters.

javascript html5

2022-09-30 11:12

1 Answers

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

What about calculation?
It's a spelling mistake.


2022-09-30 11:12

If you have any answers or tips


© 2023 OneMinuteCode. All rights reserved.