You can check if an input field exists as such:
if($("input[id$='txtHello']").length > 0) { ... }
If not, val() will return undefined .
You can immediately go to the following:
if(!!$("input[id$='txtHello']").val())
... since both undefined and "" will be allowed to false
David Hedlund
source share