1

Начал изучение JS. Столкнулся с проблемой, что результат который должен выводить JS не отображается. Что можно сделать с этой проблемой?

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <script>
        window.onload=init;

    function init(){
        var button=document.getElementById("butt");
        button.onclick=buttonHandler;
    }
    function buttonHandler(){
        var feet = document.getElementById("feet");
        var f=feet.value;
        var weight= document.getElementById("weight");
        var w=weight.value;
        var result=document.getElementById("result");
        var r=w+f;
        result.innerHTML=r;
}

    </script>
</head>
<body>
    <h1>Форма JS</h1>
    <form action="#" id="bmiCalculator">
        <label for="feet" for="inches">Height:</label>
        <input type="text" id="feet"> feet<br>

        <label for="pounds">Weight:</label>
        <input type="text" id="pounds">pounds <br><br>
        <input type="button" id="butt" value="Calculate!">
    </form>
    <p>Your BMI: <output id="result"></output></p>
</body>
</html>

1 ответ 1

0

У тебя неверное указано значение в getElementById. Ты указал getElementById("weight"), а элемент у тебя называется pounds:<input type="text" id="pounds">pounds <br> Нужно вот это:

var weight= document.getElementById("weight");

заменить на это:

var weight= document.getElementById("pounds");

И будет все работать.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.