Я пытаюсь очистить поле ввода после нажатия кнопки

1

Мне нужно, чтобы поле ввода очистилось после того, как пользователь нажимает кнопку, чтобы преобразовать номер, который они ввели. Мне сложно понять это, если кто-то может помочь, я чувствую, что это очень простое решение, но, похоже, я не могу обернуться вокруг него.

 (function () {
        //Constants
        const KM_TO_MILES = 0.625;
        const MILES_TO_KM = 1.6;

        var user = prompt("So..What your name beautiful?");
        if (user === null) {
            alert("NOOOOO, you cancel me? meanie.")
            remove();
        }

        //on load function
        window.onload = function () {
            var result = document.getElementById("result");
            //display the user name with a message prompt to continue to enter a distance
            result.innerHTML = "Okay, " + user + ", enter your distance and I will calculate for you, don't worry.";
            document.getElementById("convertBtn").onclick = startConvert;

        };
        //on load function done

        //conversion function
        function startConvert() {
            var placeholder = document.getElementById("distance").value;
            var distanceInput = document.getElementById("distance").value;
            var conversion = document.getElementById('List').value;
            document.getElementById("List").value;

            // If the user doesn't input a number run the alert
            if ((placeholder === "") || (conversion == "Select Types")) {

                alert("You didn't enter anything mate");
                // If the user inputs a number and clicks KM to M then calculate it and in the html page change the text to show the answer.
            } else if (conversion == "Kilometers to Miles") {

                document.getElementById("result").innerHTML = "Okay, " + user + " ,the distance of " + distanceInput + " is equal to " + (distanceInput * KM_TO_MILES + " miles.");

                // If the user inputs a number and clicks M to KM then calculate it and in the html page change the text to show the answer.
            } else if (conversion == "Miles to Kilometeres") {


                document.getElementById("result").innerHTML = "Okay, " + user + " ,the distance of " + distanceInput + " is equal to " + (distanceInput * MILES_TO_KM + " kilometers.");

            }


        }
        //conversion function done



    }());
  • 1
    Что означает «сброс страницы» ?
  • 1
    Я также не уверен, что вы имели в виду под «перезагрузкой страницы». Чтобы очистить поле ввода, вы можете сделать document.getElementById("distance").value = '' после преобразования.
Показать ещё 2 комментария
Теги:

1 ответ

1
Лучший ответ
document.getElementById('yourid').value = '';

вы вызываете это событие на своей кнопке, безусловно, это будет работать

Ещё вопросы

Сообщество Overcoder
Наверх
Меню