node ninja
node ninja

Reputation: 33056

Why can I set the text in a textbox but I can't clear it?

I have this written in a certain Javascript function.

document.getElementById("textbox").innerHTML = "some text";

This does what you'd expect. However, if I slightly modify it to try to clear the text box like this

document.getElementById("textbox").innerHTML = "";

It doesn't work. Why?

Upvotes: 1

Views: 88

Answers (2)

Kevin Le - Khnle
Kevin Le - Khnle

Reputation: 10887

Try

document.getElementById("textbox").value= "";

Upvotes: 2

JaredPar
JaredPar

Reputation: 755457

I'm not sure why innerHTML is working in that particular case but the more appropriate property to use is value

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

Upvotes: 3

Related Questions