Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Show/hide multiple elements with one link using javascript

Reply
Thread Tools

Show/hide multiple elements with one link using javascript

 
 
itunes66@gmail.com
Guest
Posts: n/a
 
      10-14-2005
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;
}
}

 
Reply With Quote
 
 
 
 
Stephen Chalmers
Guest
Posts: n/a
 
      10-15-2005
<(E-Mail Removed)> wrote in message news:(E-Mail Removed) 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.


 
Reply With Quote
 
 
 
 
itunes66@gmail.com
Guest
Posts: n/a
 
      10-15-2005
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

 
Reply With Quote
 
Stephen Chalmers
Guest
Posts: n/a
 
      10-15-2005
i<(E-Mail Removed)> wrote in message news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
replacing xml elements with other elements using lxml Ultrus Python 4 08-30-2007 07:17 AM
XML elements to JavaScript Array elements Conversion P XML 1 07-07-2006 09:08 PM
RE: Link Link Link =?Utf-8?B?REw=?= Windows 64bit 0 05-17-2005 12:15 PM
Re: Link Link Link DANGER WILL ROBINSON!!! Kevin Spencer ASP .Net 0 05-17-2005 10:41 AM
Using One XSLT and multiple XML Problem (One is XML and another one is XBRL) loveNUNO XML 2 11-20-2003 06:47 AM



Advertisments