0

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 
2
  • 1
    Show the html for the textbox Commented Dec 22, 2014 at 10:31
  • 1
    This question should be tagged with javascript rather than asp.net-mvc, as that is not relevant to the problem described or the code posted. Commented Dec 22, 2014 at 10:31

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.