Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Please help - Hide a table while show a table

Reply
Thread Tools

Please help - Hide a table while show a table

 
 
michael941@gmail.com
Guest
Posts: n/a
 
      12-10-2006
Hi,

I have 2 tables in an html page. I have div them separately and id them
as id1 and id2. I have a link there. What I need is click the link to
hide one table and show the other and verse when click the link again.


I tried many ways in javascript but failed. Could someone please help?

Thanks a lot!

 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      12-10-2006

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
>
> I have 2 tables in an html page. I have div them separately and id them
> as id1 and id2. I have a link there. What I need is click the link to
> hide one table and show the other and verse when click the link again.
>
>
> I tried many ways in javascript but failed. Could someone please help?


Show your last try, we'll start from there.

 
Reply With Quote
 
 
 
 
ASM
Guest
Posts: n/a
 
      12-10-2006
(E-Mail Removed) a écrit :
> Hi,
>
> I have 2 tables in an html page. I have div them separately and id them
> as id1 and id2. I have a link there. What I need is click the link to
> hide one table and show the other and verse when click the link again.
>
>
> I tried many ways in javascript but failed. Could someone please help?


<button onclick="
var id1 = document.getElementById('id1').style;
var id2 = document.getElementById('id2').style;
if(typeof(asm)=='undefined') {
// 1st time you press button : hide div 2
// asm is a pointer created at this moment
// to avoid to hide 2nd div at each next pressure
asm = true;
id2.display = 'none';
}
else
{
id1.display = id1.display==''? 'none' : '';
id2.display = id2.display==''? 'none' : '';
};">hide / show </button>

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
 
Reply With Quote
 
michael941@gmail.com
Guest
Posts: n/a
 
      12-10-2006
Hi, VK

well, actually this javascript should be working in a jsp page finally,
not html.

I am guessing jsp should not be embbed into jsp?

thanks

On Dec 10, 1:53 pm, "VK" <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > Hi,

>
> > I have 2 tables in an html page. I have div them separately and id them
> > as id1 and id2. I have a link there. What I need is click the link to
> > hide one table and show the other and verse when click the link again.

>
> > I tried many ways in javascript but failed. Could someone please help?Show your last try, we'll start from there.


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      12-10-2006
ASM wrote on 10 dec 2006 in comp.lang.javascript:

> <button onclick="
> var id1 = document.getElementById('id1').style;
> var id2 = document.getElementById('id2').style;
> if(typeof(asm)=='undefined') {
> // 1st time you press button : hide div 2
> // asm is a pointer created at this moment
> // to avoid to hide 2nd div at each next pressure
> asm = true;
> id2.display = 'none';
> }
> else
> {
> id1.display = id1.display==''? 'none' : '';
> id2.display = id2.display==''? 'none' : '';
> };">hide / show </button>



A global variable remembering the status is not even neccessary:

<script type='text/javascript'>
function swap(button,a,b) {
var x = document.getElementById(a).style;
var y = document.getElementById(b).style;
var swapper = y.display == 'none';
x.display = swapper ? 'none' : '';
y.display = swapper ? '' : 'none';
button.innerHTML = swapper ?
'hide '+b+' / show '+a :
'hide '+a+' / show '+b;
}
</script>

<button onclick="swap(this,'id1','id2')">
hide div id2</button>
<br><br>
<div id='id1'>This is id1</div>
<div id='id2'>This is id2</div>
<br><br>
<button onclick="swap(this,'id3','id4')">
hide div id4</button>
<br><br>
<div id='id3'>This is id3</div>
<div id='id4'>This is id4</div>


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
michael941@gmail.com
Guest
Posts: n/a
 
      12-10-2006
Thanks, Evertjan,

Your way works sooooooooooooo wellllll~!

Cheers

On Dec 10, 3:37 pm, "Evertjan." <(E-Mail Removed)> wrote:
> ASM wrote on 10 dec 2006 in comp.lang.javascript:
>
> > <button onclick="
> > var id1 = document.getElementById('id1').style;
> > var id2 = document.getElementById('id2').style;
> > if(typeof(asm)=='undefined') {
> > // 1st time you press button : hide div 2
> > // asm is a pointer created at this moment
> > // to avoid to hide 2nd div at each next pressure
> > asm = true;
> > id2.display = 'none';
> > }
> > else
> > {
> > id1.display = id1.display==''? 'none' : '';
> > id2.display = id2.display==''? 'none' : '';
> > };">hide / show </button>A global variable remembering the status is not even neccessary:

>
> <script type='text/javascript'>
> function swap(button,a,b) {
> var x = document.getElementById(a).style;
> var y = document.getElementById(b).style;
> var swapper = y.display == 'none';
> x.display = swapper ? 'none' : '';
> y.display = swapper ? '' : 'none';
> button.innerHTML = swapper ?
> 'hide '+b+' / show '+a :
> 'hide '+a+' / show '+b;}</script>
>
> <button onclick="swap(this,'id1','id2')">
> hide div id2</button>
> <br><br>
> <div id='id1'>This is id1</div>
> <div id='id2'>This is id2</div>
> <br><br>
> <button onclick="swap(this,'id3','id4')">
> hide div id4</button>
> <br><br>
> <div id='id3'>This is id3</div>
> <div id='id4'>This is id4</div>
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)


 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      12-10-2006
Evertjan. a écrit :
> ASM wrote on 10 dec 2006 in comp.lang.javascript:


Hi,

> A global variable remembering the status is not even neccessary:


Not too bad


--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
 
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
show hide divs - show last state upon reload/post ll Javascript 2 05-01-2008 12:15 PM
Hide/Show Issue, Please Help Erik Lautier Javascript 1 11-10-2006 07:56 PM
Swap/restore image while show/hide divs bridgemanusa@hotmail.com Javascript 4 01-27-2006 03:54 AM
DIV/IFRAME hide/show problem onMouseOut - please help :) Ryh Javascript 3 11-20-2004 12:53 PM
Please help. netscape issues with show/hide tables.. Zambien Javascript 2 10-02-2004 12:30 PM



Advertisments