-2

i just got the code below and i found that i need to do the parseInt() function..That means i need use this function to find a integer answer for my BMI answer.

<!DOCTYPE html>
<html>
<head>
    <title> 
        Calculate your BMI
    </title>


<script type=text/javascript>
function CalculateBmi(){
var weight= document.getElementsByName('weight')[0].value;
var height= document.getElementsByName('height')[0].value;

if(weight>0 && height>0){
var finalBMI=(weight/(height*height))*703;
document.getElementsByName('BMI')[0].value=finalBMI;
}
}
</script>
</head>


<body>
    <form name="Form">
    weight in pounds
    <input type="text"  name="weight" />
        <br/>
    height in inches
    <input type="text" name="height"/>
        <br/>
    <input type="button" value="calculate BMI" onclick="CalculateBmi()">
        <br />
    BMI result
    <input type="text" name="BMI"/>
    </form>

</body>
</html>

The code above is what i did, i have try to put () in the co such as

document.getElementsByName('BMI')[0].value=ParseInt(finalBMI);

but i am sure i miss something.

4

1 回答 1

3
var weight= parseInt(document.getElementsByName('weight')[0].value, 10);
var height= parseInt(document.getElementsByName('height')[0].value, 10);

Next time, please show us your attempts in the question!

于 2013-09-18T14:36:16.013 回答