Tler
Tler

Reputation: 154

How can I change the text of a input box?

I'm using this JS to try to set the text of a input box to nothing when the user clicks the clear button

// This code is not inside of the clearText function
var input = document.getElementById("input");

// this code is inside of the clearText function
input.innerHTML = "";

Here is the HTML I used for the input box and clear button:

<input id="input" type="text">

<button onclick="clearText()">Clear Factors</button>

What could I have done wrong?

Upvotes: 2

Views: 63

Answers (1)

kjpc-tech
kjpc-tech

Reputation: 570

Try out input.value = ""; Inputs are a little different then an element such as a p where the innerHTML would work as you expect. http://www.w3schools.com/jsref/prop_text_value.asp

Upvotes: 3

Related Questions