tomfmason Posted October 22, 2006 Share Posted October 22, 2006 I have been beating my head against a wall on this one... I have tired the following[code=php:0]function searchBox() { var doc = document.getElementById('search').style.display; if (doc == 'none') { doc = 'block'; } else if (doc == 'block') { doc = 'none'; } else { alert(doc); }}[/code]This always alerts undefined. I also tried adding a .value and got the same result.Any suggestions?Thanks,Tom Quote Link to comment Share on other sites More sharing options...
tomfmason Posted October 22, 2006 Author Share Posted October 22, 2006 I just thought of something... If I can't get it to work like this then I could always add a hidden input field and then update the value depending on the display state.. like this.[code=php:0]function search() { var field = document.getElementById('field').value; var doc = document.getElementById('search').style.display; if (field == 'none') { doc = 'block'; field = 'block'; }else if (field == 'none') { doc = 'none'; field = 'none'; } else { alert('There was an error'); }}[/code] Quote Link to comment Share on other sites More sharing options...
tomfmason Posted October 22, 2006 Author Share Posted October 22, 2006 That works but it is not the way that I want to do it. Can any one give me a reason that the variable doc will not return a value...? Quote Link to comment Share on other sites More sharing options...
MCP Posted October 22, 2006 Share Posted October 22, 2006 Can you just define it first? Like in your css put in display:block, and then it would be block? If you don't ever define it, it doesn't have a value, hence undefined.I agree with you that it seems logical that it should have an initial value if you don't explicitly set it in CSS (i.e. should be block (or actually inline should be the default, IIRC)). It just seems that it's not the case, so you'll have to modify your code to assume that undefined == 'block' or 'inline'. Quote Link to comment Share on other sites More sharing options...
tomfmason Posted October 22, 2006 Author Share Posted October 22, 2006 It returns nothing ether way. If I have it set to block or none.. I know that there has to be a way to do it..Thanks,Tom Quote Link to comment Share on other sites More sharing options...
tomfmason Posted October 22, 2006 Author Share Posted October 22, 2006 LOL.. I figured it out. I had the display set in the CSS.. For this I have to set it in the tag it's self.. Thanks,Tom Quote Link to comment Share on other sites More sharing options...
fenway Posted October 22, 2006 Share Posted October 22, 2006 Also, some browsers won't specify a default, but rather tell you what was explicitly requested. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.