You are accessing a property of an object that is null. var input = document.getElementById("input"); input // when this fails, it returns null. To make sure that you don't get this error, you have to make sure that btn , or any object you use, is not null before you use it.