I have tried rectifying the code below. But I am not able to find a solution. After executing the code, firebug says "document.getElementById(haystack.value) is null". I tried if(document.getElementById(haystack).value ==null) but it was of no use. Please help me out.
var haystack=document.getElementById('city1').value;
if(!document.getElementById(haystack).value)
{
alert("null");
}
else
{
alert("not null");
}
Edit:
haystack gets the value of the city. When i try an "alert" on haystack -alert(haystack) i get a positive reply. but when i try it with "document.getElementById(haystack).value" i get an error. One thing though, the element with the id that haystack gets might or might not exist.
Edit again:
I think ill kill myself. I put the city for the name attribute for an input element not the id attribute. I am sorry, but sitting in front of the computer this long made me loose my mind. But it is no excuse for having wasted your time. Please accept my sincere apologies. Thanks spender for helping me out.
haystack? What are you trying to achieve?