Enjoy an ad free experience by logging in. Not a member yet?
Register .
08-16-2010, 09:45 PM
PM User |
#1
Regular Coder
Join Date: Nov 2008
Location: The Great Pacific NW, USA
Posts: 421
Thanks: 8
Thanked 6 Times in 6 Posts
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 ..
08-16-2010, 09:56 PM
PM User |
#2
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
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.
08-16-2010, 09:56 PM
PM User |
#3
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
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
08-16-2010, 09:59 PM
PM User |
#4
Regular Coder
Join Date: Nov 2008
Location: The Great Pacific NW, USA
Posts: 421
Thanks: 8
Thanked 6 Times in 6 Posts
Thanks to both of you.
08-16-2010, 10:05 PM
PM User |
#5
Regular Coder
Join Date: Nov 2008
Location: The Great Pacific NW, USA
Posts: 421
Thanks: 8
Thanked 6 Times in 6 Posts
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 ..
08-16-2010, 10:14 PM
PM User |
#6
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
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.
08-16-2010, 10:44 PM
PM User |
#7
Regular Coder
Join Date: Nov 2008
Location: The Great Pacific NW, USA
Posts: 421
Thanks: 8
Thanked 6 Times in 6 Posts
And ... for his next trick, he will walk and chew gum
at the same time !!!
08-17-2010, 08:13 AM
PM User |
#8
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Quote:
Originally Posted by
mOrloff
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.
08-17-2010, 08:15 PM
PM User |
#9
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
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.
08-17-2010, 11:34 PM
PM User |
#10
Regular Coder
Join Date: Nov 2008
Location: The Great Pacific NW, USA
Posts: 421
Thanks: 8
Thanked 6 Times in 6 Posts
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 ;-)' ;
}
Jump To Top of Thread
Thread Tools
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
HTML code is Off
All times are GMT +1. The time now is 03:53 AM .
Advertisement
Log in to turn off these ads.