Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-16-2010, 09:45 PM   PM User | #1
mOrloff
Regular Coder

 
mOrloff's Avatar
 
Join Date: Nov 2008
Location: The Great Pacific NW, USA
Posts: 421
Thanks: 8
Thanked 6 Times in 6 Posts
mOrloff is an unknown quantity at this point
Visibility control question from a COMPLETE noob.

Every year or two, I want to do something SIMPLE via JS, and each time it's like i've never been there before

I simply want a button to show/hide something on click, and I THINK I'm close, but it's not quite working.

Here's what I'm toying with.
Code:
<html>
  <head>
    <script type="text/javascript">
      function showHide("idName") {
        if(document.getElementById("idName").style.visibility=="hidden") {
          document.getElementById("idName").style.visibility=="visible";
        }
        else {
          document.getElementById("idName").style.visibility=="hidden";
        }
      }
    </script>
  </head>
  <body>
    <button type="button" onclick="showHide(1)">Click Me!</button>
    <div id="1" "style=visibility:hidden;"><p>this is the stuff.</p></div>
  </body>
</html>
How do I get the button to make that div (in)visible??
~Mo

Last edited by mOrloff; 08-16-2010 at 10:09 PM..
mOrloff is offline   Reply With Quote
Old 08-16-2010, 09:56 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Code:
    <div id="D1" style="visibility:hidden;"><p>this is the stuff.</p></div>
Not a JS problem. An HTML problem. And don't use id's that start with digits.

And then:
Code:
<html>
  <head>
    <script type="text/javascript">
      function showHide(id) {
        var div = document.getElementById(id);
        div.style.visibility = ( div.style.visiblity == "hidden") ? "visible" : "hidden";
      }
    </script>
  </head>
  <body>
    <button type="button" onclick="showHide('D1')">Click Me!</button>
    <div id="D1" style="visibility:hidden;"><p>this is the stuff.</p></div>
  </body>
</html>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 08-16-2010, 09:56 PM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Do please read the posting guidelines regarding silly thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose. You can (and should) edit it to make it more meaningful.

<div id="1" An id must start with a letter, not a number.

"style=visibility:hidden;"> should be style="visibility:hidden">



It is your responsibility to die() if necessary….. - PHP Manual
Philip M is offline   Reply With Quote
Old 08-16-2010, 09:59 PM   PM User | #4
mOrloff
Regular Coder

 
mOrloff's Avatar
 
Join Date: Nov 2008
Location: The Great Pacific NW, USA
Posts: 421
Thanks: 8
Thanked 6 Times in 6 Posts
mOrloff is an unknown quantity at this point

Thanks to both of you.
mOrloff is offline   Reply With Quote
Old 08-16-2010, 10:05 PM   PM User | #5
mOrloff
Regular Coder

 
mOrloff's Avatar
 
Join Date: Nov 2008
Location: The Great Pacific NW, USA
Posts: 421
Thanks: 8
Thanked 6 Times in 6 Posts
mOrloff is an unknown quantity at this point
Pedant, is that tested code?
I'm still coming up shy of the mark, even with a direct copy/paste of this code.

Last edited by mOrloff; 08-16-2010 at 10:15 PM..
mOrloff is offline   Reply With Quote
Old 08-16-2010, 10:14 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Wasn't tested. Just fixed your obvious errors.

And then made a typo:
Code:
        div.style.visibility = ( div.style.visiblity == "hidden") ? "visible" : "hidden";
put the missing "i" in there after the "b" and it will work.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 08-16-2010, 10:44 PM   PM User | #7
mOrloff
Regular Coder

 
mOrloff's Avatar
 
Join Date: Nov 2008
Location: The Great Pacific NW, USA
Posts: 421
Thanks: 8
Thanked 6 Times in 6 Posts
mOrloff is an unknown quantity at this point
And ... for his next trick, he will walk and chew gum at the same time !!!
mOrloff is offline   Reply With Quote
Old 08-17-2010, 08:13 AM   PM User | #8
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by mOrloff View Post
And ... for his next trick, he will walk and chew gum at the same time !!!
Nah, too difficult for an American who is below the rank of President.
Philip M is offline   Reply With Quote
Old 08-17-2010, 08:15 PM   PM User | #9
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Philip: You don't seem to understand "rank" as applied to Americans: *EVERY* American thinks that they rank higher than President. They clearly think they know better than the President how the country should be run. So the President is at the bottom, with Senator just barely above him, and so on. <grin style="sad, but true" />
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 08-17-2010, 11:34 PM   PM User | #10
mOrloff
Regular Coder

 
mOrloff's Avatar
 
Join Date: Nov 2008
Location: The Great Pacific NW, USA
Posts: 421
Thanks: 8
Thanked 6 Times in 6 Posts
mOrloff is an unknown quantity at this point
PHP Code:
if($factAboutAmericans==TRUE && $sad==TRUE){
    echo 
'I probably shouldn\'t be laughing at this.';
}else{
    echo 
'Denial isn\'t only a river in Egypt ;-)';

mOrloff is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:53 AM.


Advertisement
Log in to turn off these ads.