Compruebe si existe una identificación JavaScript

 var myEle = document.getElementById("myElement");
    if(myEle){
        var myEleValue= myEle.value;
    }

//the return of getElementById is null if an element is not actually 
//present inside the dom, so your if statement will fail, because null 
//is considered a false value
Glorious Grouse