Kam
Kam

Reputation: 44

I'm trying to clear the input field after the button is clicked

I need the input field to clear after the user clicks the button to convert the number they've entered. I'm having a difficult time figuring this out, if anyone can help i feel like it's a very simple solution but, I can't seem to wrap my head around it.

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

        var user = prompt("So..What's 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's 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



    }());

Upvotes: 1

Views: 78

Answers (1)

Udhay Titus
Udhay Titus

Reputation: 5869

document.getElementById('yourid').value = '';

you call this event on your button click surely it'll be works

Upvotes: 1

Related Questions