473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Please help - Hide a table while show a table

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!

Dec 10 '06 #1
6 1973
VK

mi********@gmail.com 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.

Dec 10 '06 #2
ASM
mi********@gmail.com 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
Dec 10 '06 #3
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" <schools_r...@yahoo.comwrote:
michael...@gmail.com 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.
Dec 10 '06 #4
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)
Dec 10 '06 #5
Thanks, Evertjan,

Your way works sooooooooooooo wellllll~!

Cheers

On Dec 10, 3:37 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
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)
Dec 10 '06 #6
ASM
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
Dec 10 '06 #7

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

Similar topics

2
by: John M | last post by:
I want to hide the first row in my table and if a user click on a show button than show it. If it is visible than user can hide it with click a hide button. In default I hide it with: <tr...
7
by: Mad Scientist Jr | last post by:
Through messing around I got IE6 (win xp) to show/hide a table row. I gave my <TR> an ID of "trRow" and trRow.style.display='none'; hides it trRow.style.display='block'; displays it (will any...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
10
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...
1
by: Oliver Hoehle | last post by:
Hello! This ist the source-code for an editable combobox implemented with HTML,CSS and Javascript. I have tested it with IE and Mozilla. But I don't know, if it will work in other browsers...
2
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 {...
5
by: Dautkhanov | last post by:
Hello all ! I have my own library for web-design building - active forms, lists. I am going to build tabbing component. The complexity in this process is that all web forms uniformed and are...
1
by: pamate | last post by:
hi, I want to show hide layers. I am able to show and hide layers but i am facing problem that, cant view the cursor in Mozilla,but i can type in input text box, its overlapping the layers. ...
18
by: Liquidtouch | last post by:
I have been searching on this for awhile and cant find anything and playing around with it got me no where. I will start with what I am after and then explain what I have. I have a table with 3...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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...

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.