I am trying to calculate Body Mass Index by receiving Weight and Height from HTML form and passing it to JavaScript code by .getElementById();. But, as far as I understand, type of data received from form is "string" and I need to receive a "number". How can I solve this problem?
Asked
Active
Viewed 93 times
0
-
`parseInt()` and `parseFloat()` should help you – Sirko Dec 22 '15 at 12:56
-
yes or multiple with 1 – Ashish Kumar Dec 22 '15 at 12:58
3 Answers
0
var a = document.getElementById("whatever").value;
// You can use any 3
+a; // Unary Operator
parseInt(a, 10); // parseInt with radix 10
Number(a);

void
- 36,090
- 8
- 62
- 107
0
you can use function parseInt(string) that Convert string into int .Now in your senario :- var weight_str = document.getElementByID("weight"); var weight_int = parseInt(weight_str);
this will give you the result.

Shubham Akodiya
- 1
- 1