Nik
Nik

Reputation: 1

clear textbox but giving error using java script

I'm trying to clear textbox by using this javascript code:

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

or:

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

both are not working .just getting error like this:

typeerror document.getelementbyid(...) is null 

Upvotes: 0

Views: 56

Answers (1)

Lajos Arpad
Lajos Arpad

Reputation: 76424

Right click on the element and look at the generated HTML in your browser. Probably you do not have a txtUnit there, as txtUnit is the server-side id. You need to refer to it as txtUnit.ClientID.

EDIT: More information

getElementById is null if the id was not found in your HTML. You must make sure that you have the id there and that your element was already created when you try to find it by id.

Upvotes: 1

Related Questions