Why can't I get this javascript code work?

Adam Jones

I have written a web page in JavaScript that calculates your BMI and it seems to work but when I hit the calculate button an alert box pops up and says "your BMI is NaN". I know NaN stands for not a number. I just want to know why I can't get this to work.

<!DOCTYPE html>

<html>
<head>

    <title>BMI</title>

</head>

<body>
    <p>Your weight:<input type="number" id="value1" /></p>

    <p>Your height (in inches):<input type="number" id="value2" /></p>

<script>

    function calc() {
    var data1 = document.getElementById("value1");
    var data2 = document.getElementById("value2");
    var weight = (data1 * 703);
    var height = (weight) / (data2 * data2);
    alert("Your BMI is " + height);
    };

    </script>

    <button onclick="calc()">Calculate</button>

</body>
</html>
Brad

Here's a fiddle: http://jsfiddle.net/wYfq8/

function calc() {
    var data1 = document.getElementById("value1").value;
    var data2 = document.getElementById("value2").value;
    var weight = (data1 * 703);
    var height = (weight) / (data2 * data2);
    alert("Your BMI is " + height);
};

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why can't I get my JavaScript replace function to work?

From Dev

Why I can't get input value in my javascript code

From Dev

Why can't I get `< and `> to work in MacVim?

From Dev

Why can't I get these extensions to work?

From Dev

Why can't I get `< and `> to work in MacVim?

From Dev

I can't get my CSS code to work properly

From Dev

Why can't I get HAL support to work in grails 2.3.8?

From Dev

Why can't I get Google's Python test to work?

From Dev

Why can't I get convolution to work properly in MATLAB?

From Dev

Why can't I get functional methods to work?

From Dev

Why can't I get HAL support to work in grails 2.3.8?

From Dev

Why can't my javascript code in the head selection get an element?

From Dev

why I can't get value of label with jquery and javascript?

From Dev

Why can't I get properties count of navigator object in JavaScript?

From Dev

Why can't I get properties count of navigator object in JavaScript?

From Dev

Why can't .getUrl work in this code?

From Dev

Javascript code doesn't work. Why?

From Dev

Can't get sample code to work

From Dev

Can't get code to work in PHP 5.5.9

From Dev

Can't get Python class code to work

From Dev

I can't figure out why this piece of code does not work (null pointer exception)

From Dev

I can't make these few simple line of code work correctly and have no idea why

From Dev

Why can I retrive an image with absolute path in XAML but it doesn't work behind code?

From Dev

JavaScript in VS Code: why can't I collapse the 'case' code blocks in my 'switch' statements?

From Dev

Can't get these javascript if statements to work

From Dev

Can't get this Javascript query to work

From Dev

Can't get these javascript if statements to work

From Dev

I can't get onclick to work

From Dev

I can't get phpseclib to work

Related Related

  1. 1

    Why can't I get my JavaScript replace function to work?

  2. 2

    Why I can't get input value in my javascript code

  3. 3

    Why can't I get `< and `> to work in MacVim?

  4. 4

    Why can't I get these extensions to work?

  5. 5

    Why can't I get `< and `> to work in MacVim?

  6. 6

    I can't get my CSS code to work properly

  7. 7

    Why can't I get HAL support to work in grails 2.3.8?

  8. 8

    Why can't I get Google's Python test to work?

  9. 9

    Why can't I get convolution to work properly in MATLAB?

  10. 10

    Why can't I get functional methods to work?

  11. 11

    Why can't I get HAL support to work in grails 2.3.8?

  12. 12

    Why can't my javascript code in the head selection get an element?

  13. 13

    why I can't get value of label with jquery and javascript?

  14. 14

    Why can't I get properties count of navigator object in JavaScript?

  15. 15

    Why can't I get properties count of navigator object in JavaScript?

  16. 16

    Why can't .getUrl work in this code?

  17. 17

    Javascript code doesn't work. Why?

  18. 18

    Can't get sample code to work

  19. 19

    Can't get code to work in PHP 5.5.9

  20. 20

    Can't get Python class code to work

  21. 21

    I can't figure out why this piece of code does not work (null pointer exception)

  22. 22

    I can't make these few simple line of code work correctly and have no idea why

  23. 23

    Why can I retrive an image with absolute path in XAML but it doesn't work behind code?

  24. 24

    JavaScript in VS Code: why can't I collapse the 'case' code blocks in my 'switch' statements?

  25. 25

    Can't get these javascript if statements to work

  26. 26

    Can't get this Javascript query to work

  27. 27

    Can't get these javascript if statements to work

  28. 28

    I can't get onclick to work

  29. 29

    I can't get phpseclib to work

HotTag

Archive