473,670 Members | 2,499 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to expand and hide sub-button

Hi,

I'm wondering how to use javascript to do something like:
TOP_Button

when clicking on it, it becomes:

TOP_Button
sub_button_1
sub_button_2

and clicking TOP_Button again, two sub_buttons get hidden.

but clicking on sub_button, it should not be hidden.

--
Thanks
John
Toronto

Jan 10 '06 #1
9 2717
john_woo escreveu:
TOP_Button

when clicking on it, it becomes:

TOP_Button
sub_button_1
sub_button_2

and clicking TOP_Button again, two sub_buttons get hidden.


http://www.google.com.br/search?q=show+hide+javascript :)
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com

Jan 10 '06 #2
Use the button element's hidden attribute, for example:

function unHideButton(bu ttonID)
{
node = document.getEle mentById("butto nID");
node.style.hidd en = "visible";
}

function hideButton(butt onID)
{
node = document.getEle mentById("butto nID");
node.style.hidd en = "hidden";
}

Jan 10 '06 #3
ph*******@gmail .com wrote:
Use the button element's hidden attribute, for example:
No, don't. An HTML button element doesn't have a 'hidden' attribute and
there is no CSS 'hidden' property, though the visibility property can
have a value of 'hidden'.

<URL: http://www.w3.org/TR/CSS21/visufx.ht...def-visibility >


function unHideButton(bu ttonID)
{
node = document.getEle mentById("butto nID");
There doesn't seem to be any need to make 'node' global, so keep it local.

var node = document.getEle mentById("butto nID");

node.style.hidd en = "visible";
if (node) node.style.visi bility = "visible";
or

node && node.style.visi bility = "visible";
getElementById and support for the element's style object should be
feature tested.

The best way is to add functions dynamically so that if the appropriate
features aren't supported, the functions that require them aren't called
and the browser is left in a state that allows it to function without them.

Guessing that the functions are to be run using an onclick, all the
buttons could be made visible by default and a script used to detect
features and then add the functions and modify their style if appropriate.

}

function hideButton(butt onID)
{
node = document.getEle mentById("butto nID");
node.style.hidd en = "hidden";
var node = document.getEle mentById("butto nID");
node && node.style.visi bility = "hidden";
}

--
Rob
Jan 11 '06 #4
john_woo wrote:
Hi,

I'm wondering how to use javascript to do something like:
TOP_Button

when clicking on it, it becomes:

TOP_Button
sub_button_1
sub_button_2

and clicking TOP_Button again, two sub_buttons get hidden.

but clicking on sub_button, it should not be hidden.
If you are trying to create an hierarchical menu system, there are lots
of those around (though they're mostly pretty awful).

<URL:
http://search.atomz.com/search/?sp-q...p=All&sp-k=All


The example below does what you want, you should be able to modify it
fairly easily to use buttons if that's what's really needed.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> new document </title>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">

<style type="text/css">
..clickable {
cursor: pointer;
color: #00f;
background-color: #fff;
text-decoration: underline;
}
</style>

<script type="text/javascript">
function initList(id)
{
// Check features before applying modifications
if ( !document.getEl ementById
|| !document.getEl ementsByTagName ) {
return;
}

// Get the button
var topBtn = document.getEle mentById(id);

// More feature testing
if (!topBtn.style || !topBtn.parentN ode) return;

// Get it's LI parent
var btnParent = getParentByTagN ame(topBtn, 'li');
if (!btnParent) return;

// Get the first UL child node
var btnSet = btnParent.getEl ementsByTagName ('ul')[0];

// If next test OK, do changes else do nothing
if (btnSet){
topBtn.classNam e = 'clickable';
toggleVis(btnSe t);
topBtn.onclick = function(){togg leVis(btnSet);}
}
}

function getParentByTagN ame(el, nn)
{
nn = nn.toLowerCase( );
while (el.parentNode && nn != el.nodeName.toL owerCase() ){
el = el.parentNode;
}
return (nn == el.nodeName.toL owerCase())? el : null;
}

function toggleVis(el)
{
// x introduced to prevent wrapping
var x = el.style;
x.visibility = ('hidden' == x.visibility)? 'visible' : 'hidden';
}

</script>
</head>
<body>
<ul>
<li><span id="topButton"> LTOP_Button</span>
<ul>
<li>sub_button_ 1</li>
<li>sub_button_ 2</li>
</ul>
</li>
</ul>

<script type="text/javascript">
initList('topBu tton');
</script>

</body>
</html>
initList could be assigned to the body onload event, however if the
document is large and takes some time to load, the list of buttons might
be displayed for a short time before being hidden.

Putting it where it is means it will run as soon as the relevant
elements have been created. You may also want to look at the CSS
display property which can be toggled between 'none' and '' to hide and
show elements respectively.

--
Rob
Jan 11 '06 #5
I got it:

<form>
<input type="button" value="big" onclick="showHi de();" />
<input type="button" value="sub_1" id="b1" />
<input type="button" value="sub_2" id="b2" />
</form>

<SCRIPT LANGUAGE="JavaS cript">
<!--
function showHide() {
if (document.getEl ementById('b1') .style.visibili ty != "hidden")
{
document.getEle mentById('b1'). style.visibilit y = "hidden";
document.getEle mentById('b2'). style.visibilit y = "hidden";
}
else {
document.getEle mentById('b1'). style.visibilit y = "visible";
document.getEle mentById('b2'). style.visibilit y = "visible";
}
}
//-->
</SCRIPT>

but still wondering whether it works in all browsers.

Jan 11 '06 #6
john_woo wrote:
I got it:
No, you don't.
<form>
`form' elements require the `action' attribute.
<input type="button" value="big" onclick="showHi de();" /> ^
IE does not support XHTML. Declare HTML; omit the "/", you do not
need it and it is potentially harmful if you include it in HTML as
`<foo />' is equivalent to `<foo>&gt;' there.

Should be

<input type="button" value="big" onclick="showHi de(this);">
<input type="button" value="sub_1" id="b1" />
<input type="button" value="sub_2" id="b2" />
</form>

<SCRIPT LANGUAGE="JavaS cript">
<!--
That is utter nonsense, search the archives. Should be

<script type="text/javascript">
function showHide() {
if (document.getEl ementById('b1') .style.visibili ty != "hidden")
{
document.getEle mentById('b1'). style.visibilit y = "hidden";
document.getEle mentById('b2'). style.visibilit y = "hidden";
}
else {
document.getEle mentById('b1'). style.visibilit y = "visible";
document.getEle mentById('b2'). style.visibilit y = "visible";
}
}
That is nonsense as well. Should be at least

function showHide(o)
{
var b1 = o.form.elements['b1'];
var b2 = o.form.elements['b2'];

if (b1 && typeof b1.style != "undefined" && b2)
{
var b = (b1.style.visib ility != "hidden");
b1.style.visibi lity = b ? "hidden" : "visible";
b2.style.visibi lity = b ? "hidden" : "visible";
}
}
//-->
Unnecessary.
</SCRIPT>

but still wondering whether it works in all browsers.


It does not, but the corrected version at least should not break.
PointedEars
Jan 11 '06 #7
Thanks lots for the correction.

Can u tell what's the right idea to implement a javascript function to
achive such goal and make it work over various browsers?

--
John
Toronto

Jan 11 '06 #8
john_woo wrote:
Thanks lots for the correction.
You're welcome.
Can u tell what's the right idea to implement a javascript function to
achive such goal and make it work over various browsers?
Pardon? I just did.
--
[...]


If that should be a signature, it has to be separated with dashDashSPACE.
I am not sure if Google Groups is capable of leaving the trailing space
alone.
PointedEars
Jan 11 '06 #9
<i>hidden</i> was a typo, oops.

Jan 13 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
74076
by: genetic.error | last post by:
I'm moving from Vb6 to VB.Net. I have a feeling this has come up before... The VS.Net MSDN file seems to state that the following should work: Form1.Show Form1.Visible = True Form1.Hide Form1.Visible = False Load (Form1)
7
17210
by: peter | last post by:
I use the click-to-expand menu at http://javascript.internet.com/navigation/click-to-expand-menu.html This works fine, but is there a way to expand or collapse all the menus? An example of how I use this is here: http://www.cod.edu/people/faculty/chenpe/PRAIRIE/index.html Thanks!
7
4534
by: Darin | last post by:
I have a report that sub-totals on a group, then grand-totals at the report footer. If there's only one group, the sub-total and grand total are redundant, so I only want to show one of them. I know how to count the groups, then hide the report footer if there's only one group, but my problem is I want to hide the group footer (sub-total), not the report footer (because the report footer references what the grand total is for, which is...
1
4316
by: Steven | last post by:
Hello, I have a problem in using TreeView. I want to know how the TreeView can automatically Expand a path I have accessed before? I have tried to use "path.Expand()", but it seems no good working. Does anyone can give me any advise or show me somecode for sample?. Thanks.
2
2679
by: Jenny | last post by:
My codebehind file contains a lot of sub's. Is there a fast way to expand and collapse them in the VisualStudio? It's really exhausting to collapse them all after opening the project in the morning! Thanks Jenny
5
2246
by: Kirk Graves | last post by:
Can anyone tell me why this code does not work? Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Hide() End Sub If runs, but the form won't hide itself. This is the main form of the application.
4
9158
by: Matthew | last post by:
The following code does not hide the form. Any ideas why? Also, is there a workaround? I have VB.NET 2003. I have a system tray icon, and want to have that be the only thing showing when the program starts. Matthew
4
1554
by: BrianDH | last post by:
Hi I have an application with 3 windows forms. One of which I load at startup but hide, then show/hide based on users click. How can I test to see if the windows is hidden, or is at the moment being shown? Thanks BrianDH
4
7445
by: Marcolino | last post by:
Hi I have a little problem with Treeview expand. So I'll try to explain. I Have one node and some subnodes like this +Nodes1 |------Subnodes 1 |------Subnodes 2 +Nodes2
0
8468
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8901
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8814
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8660
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6213
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4209
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1792
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.