I want the label with id="risultato" display the area of triangle,I tried to make this,but when I pressed button "risultato:" the risult is NaN,why? Thanks lots
Asked
Active
Viewed 81 times
-6
-
Please do not post your code in Image format. Can you please add your code in textual format? – Sayali Sonawane Sep 27 '16 at 17:16
-
You should use `base.value` and `altezza.value`. They are input elements, so the `value` fields contains the actual input – eavidan Sep 27 '16 at 17:16
-
`value` is missing. `NaN` means its not a number. Since you are not taking value, its not getting integer and hence the error. – Kinshuk Lahiri Sep 27 '16 at 17:19
1 Answers
2
You are getting NaN because of this:
var altezza = document.getElementById('altezza');
var base = document.getElementById('base');
(base*altezza/2)
getElementById() does exactly that - gets the element. You just need to get the value from the element e.g. var altezza = document.getElementById('altezza').value;

Gavin
- 4,365
- 1
- 18
- 27