Jump to content


Photo

determine display state??


  • Please log in to reply
6 replies to this topic

#1 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 22 October 2006 - 08:28 AM

I have been beating my head against a wall on this one... I have tired the following

function searchBox() {
     var doc = document.getElementById('search').style.display;
     if (doc == 'none') {
         doc = 'block';
     } else if (doc == 'block') {
         doc = 'none';
     } else {
         alert(doc);
     }
}

This always alerts undefined.

I also tried adding a .value and got the same result.

Any suggestions?

Thanks,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 22 October 2006 - 08:41 AM

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.

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');
     }
}

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 22 October 2006 - 09:23 AM

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...?

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#4 MCP

MCP
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 22 October 2006 - 12:42 PM

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'.

#5 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 22 October 2006 - 05:40 PM

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

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#6 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 22 October 2006 - 05:46 PM

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

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#7 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 22 October 2006 - 09:26 PM

Also, some browsers won't specify a default, but rather tell you what was explicitly requested.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users