Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Javascript visibility function
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Topic ClosedJavascript visibility function

 Post Reply Post Reply Page  12>
Author
ub3rl337ch3ch View Drop Down
Senior Member
Senior Member
Avatar

Joined: 16 February 2005
Location: Australia
Status: Offline
Points: 341
Direct Link To This Post Topic: Javascript visibility function
    Posted: 06 April 2005 at 12:03am
I'm trying to set up a function to change the visibility of a named element. Here are two attempts below:
 
function Visibility(val) {
document.getElementById('val').style.visibility = "hidden";
}
 
function Visibility(val) {
var gt=getElementById(val);
document.gt.style.visibility = "hidden";
}
 
when i try to call the function using onclick="Visibilty(menu) (where menu is the id of a layer), it gives me and 'object expected' error.
Back to Top
Phat View Drop Down
Senior Member
Senior Member


Joined: 23 February 2003
Status: Offline
Points: 386
Direct Link To This Post Posted: 06 April 2005 at 12:32am
try

<script type="text/javascript">

function hide(DivID) {
document.getElementById(DivID).style.display = "none";
}

function show(DivID) {
document.getElementById(DivID).style.display = "inline";

}

</script>

with

onClick="show('DivID')" -- replace DivID witht the name of the element
Back to Top
bootcom View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 February 2005
Location: United Kingdom
Status: Offline
Points: 259
Direct Link To This Post Posted: 06 April 2005 at 7:05am
Nice, but you can do it all in one function, like so:
 

function hideShowElement(elID){
// If the element is currently not being shown then, show the
// element
if(document.getElementById(elID).style.display == "none"){
document.getElementById(elID).style.display = "";
return;
}
// Else if the element is being shown then hide it
document.getElementById(elID).style.display = "none";
return;
}
 
onClick="hideShowElement('DivID')"
 
It's a function I use a lot, but just to overstate the obvious here, using document.getElementById doesn't work on all browsers (include a document.all) for complete compatiability.
 
Easy enough function to modify. Have fun !
Back to Top
ub3rl337ch3ch View Drop Down
Senior Member
Senior Member
Avatar

Joined: 16 February 2005
Location: Australia
Status: Offline
Points: 341
Direct Link To This Post Posted: 06 April 2005 at 7:09pm

It was obviously taking issue to the visibility property, becuase display worked fine. I ended up changing it around a bit to be:

 
function display(DivID,onoff){
if (onoff == "off"){
document.getElementById(DivID).style.display = "none";
}
if (onoff == "on"){
document.getElementById(DivID).style.display = "inline";
}
}
 
which works nicely with onclick="display('menu','off')" to turn menu off
 
is there a cross-platform function that does the same thing? or a function that i can physically put in my code that all platforms will register? more out of interest than need atm, because I'm working on this for a very small group of ie-users...
Back to Top
ub3rl337ch3ch View Drop Down
Senior Member
Senior Member
Avatar

Joined: 16 February 2005
Location: Australia
Status: Offline
Points: 341
Direct Link To This Post Posted: 06 April 2005 at 8:35pm

'inline'  isn't working, and neither is '' turn the layer back on.

I get an 'object required' error. I was wondering if this has anything to do with the fact that the layers that i am trying to show are hidden when the page loads?
Back to Top
Phat View Drop Down
Senior Member
Senior Member


Joined: 23 February 2003
Status: Offline
Points: 386
Direct Link To This Post Posted: 06 April 2005 at 10:02pm
I am not much of a javascripter but i would say you're trying to hide something by the wrong name. JS is also case sensitive.

I have a page which loads with hidden span tags which i can hide and show no problem.
Back to Top
ub3rl337ch3ch View Drop Down
Senior Member
Senior Member
Avatar

Joined: 16 February 2005
Location: Australia
Status: Offline
Points: 341
Direct Link To This Post Posted: 06 April 2005 at 11:21pm
ok, i've finally got the thing working properly, except for Angry ONE Angry SINGLE Angry LAYER Angry which refuses to be shown...
 
my function:
 
function display(DivID,onoff){
if (onoff == "off"){
document.getElementById(DivID).style.visibility = 'hidden';
}
if (onoff == "on"){
document.getElementById(DivID).style.visibility = 'visible';
}
}
 
my call:
onclick="display('submissionlayer','on')"
 
my div:
id="submissonlayer"
 
the error:
Object required, line 45


Edited by ub3rl337ch3ch - 06 April 2005 at 11:24pm
Back to Top
Phat View Drop Down
Senior Member
Senior Member


Joined: 23 February 2003
Status: Offline
Points: 386
Direct Link To This Post Posted: 06 April 2005 at 11:36pm
no idea may need to see the whole page. Got a link?
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.