473,508 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Show/hide multiple elements with one link using javascript

how can i do this i already have a function to show/hide elements with
one link but how can i show/hide multiple elements

here is the script

function obj_ref(object)
{
if (document.getElementById)
{
return document.getElementById(object);
}
else if (document.all)
{
return eval('document.all.' + object);
}
else
{
return false;
}
}

function obj_toggle(object, open_close, open_text, close_text)
{
var object = obj_ref(object);
var icone = obj_ref(open_close);

if( !object.style )
{
return false;
}

if( object.style.display == 'none' )
{
object.style.display = '';
icone.innerHTML = close_text;
}
else
{
object.style.display = 'none';
icone.innerHTML = open_text;
}
}

Oct 14 '05 #1
4 8708
<it******@gmail.com> wrote in message news:11**********************@g44g2000cwa.googlegr oups.com...
how can i do this i already have a function to show/hide elements with
one link but how can i show/hide multiple elements


A maintainable solution would be to create an array of objects, each element consisting
of the parameter list for each function call:

var paramTable=[{id : 'objId1', otherId : 'something', openText : 'xxx', closeText : 'yyy'}, {......}, ........ ];

Then have your link call a function that loops through the array passing each list to obj_toggle( )
in turn.

for(var i=0; i < paramTable.length; i++)
with( paramTable[i] )
obj_toggle( id, otherId, openText, closeText );
A couple of points regarding your code:

obj_ref() would be better returning null on failure rather than false, and its return value
should be tested in obj_toggle() before checking for its .style property.

--
S.C.
Oct 15 '05 #2
well i got that code off my forum and modified it to change txt and not
an icon but can you give me an example of you code like a full code
example like i posted

Oct 15 '05 #3
i<it******@gmail.com> wrote in message news:11**********************@o13g2000cwo.googlegr oups.com...
well i got that code off my forum and modified it to change txt and not
an icon but can you give me an example of you code like a full code
example like i posted


I don't know your parameter values so you must substitute them yourself
in the table below.
If you add more elements, maintain the exact syntax used; don't put a
comma after the last element.
A suitable HTML link is shown at the bottom.

<script type='text/javascript'>

function multiToggle()
{
var paramTable=[

{id : 'objId1', openClose : 'dunno1', openText : 'xxx', closeText : 'yyy'},
{id : 'objId2', openClose : 'dunno2', openText : 'xxx', closeText : 'yyy'},
{id : 'objId3', openClose : 'dunno3', openText : 'xxx', closeText : 'yyy'}

];

for(var i=0; i < paramTable.length; i++)
with( paramTable[i] )
obj_toggle( id, openClose, openText, closeText );

}

// All your original code here

</script>

<A href='#' onclick='multiToggle();return false'>Toggle Visibility</A>
--
Stephen Chalmers http://makeashorterlink.com/?H3E82245A
Oct 15 '05 #4
<a href="#" class="navlink" onclick="obj_toggle('titlelinks',
'show_hide_nav_controller', 'Show Nav', 'Hide Nav');"><span
id="show_hide_nav_controller">Hide Nav</span></a>

is the code i used to trigger the link to show and hide the navigation
inside a p element and also i need to be able to define the objects in
the function multi toggle and i need it to have infinite number of
things it can toggle kinda like an array

e.g.
say i had 2 elements with the same id i need them both to be toggled
basically it is obj_toggle except it can toggle multiple elements (i am
using this for the <tr> element) at one time

Oct 15 '05 #5

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

Similar topics

10
4625
by: oLE | last post by:
I would like to add some javascript to show/hide a certain row of a table. The first row of the table contain the hyperlink that calls the javascript the second row is the one i want to show/hide...
2
12168
by: MOHSEN KASHANI | last post by:
Hi, I am trying to hide some form elements in a form by default and show/hide depending on which radio button is clicked. This is what I have but it is not working: <head> <style> ..noshow {...
3
2930
by: alex | last post by:
I'd like to have a show/hide widget on my web site, kind of like "show details" / "hide details" in Google Groups. Is there a tutorial explaining how to make them? Google's is a bit complex and...
4
7982
by: jerryyang_la1 | last post by:
I've found this script that allows be to hide/show form elements.. <script language="JavaScript"><!-- var toggle = true; function show(object) { if (document.layers && document.layers)...
4
4214
by: bridgemanusa | last post by:
Hi All: I have a very long page of html that I want to take portions and hide them in divs, then show when a link is clicked. I have the hide show part working when the link is clicked, however...
1
16724
by: asilverpeach | last post by:
Hey Guys! Found some great scripts here on this topic but have to make to changes to the code that I can't seem to figure out. First, In the following code clicking on the headers shows the...
5
8411
by: ali | last post by:
Hello every one i need you help regarding div hide and show. i am having a link like <a href="#" onClick="expandWin()">show/hide </a> <div id=showHide> </div> within div i have lots of...
2
2126
by: dusk | last post by:
Hi, I have a page with lots of hidden divs which are revealed based on choices made at each 'layer'. So I've used naming convention which represents the order in which each div becomes...
1
3782
oranoos3000
by: oranoos3000 | last post by:
hi would you please help me i have a online shopping center that i show pictures of the my product in home page. in the InterExplorer pictures is shown correctly but in Firefox browser is shown...
0
7224
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,...
0
7380
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...
1
7039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7494
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...
1
5050
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...
0
3192
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...
0
1553
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
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...

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.