473,748 Members | 4,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

collapse and uncollapse tables

<table width="225" border="0">
<tr>
<td width="10" id="MyCell1"
onclick="ShowHi de('MyRow1','My Cell1')"><img
src="images/plus3.gif"></td>
<td width="205">bla hasdfadfadfasd</strong></a></div></td>
</tr>
<tr id="MyRow1">
<td>&nbsp;</td>
<td>
<table width="100%" border="0">
<tr>
<td>teadasdgads f</a></td>
</tr>
</table>
</td></tr>
<tr>
<td width="10" id="MyCell2"
onclick="ShowHi de('MyRow2','My Cell2')"><img
src="images/plus3.gif"></td>
<td width="205">bla hasdfadfadfasd</strong></a></div></td>
</tr>
<tr id="MyRow2">
<td>&nbsp;</td>
<td>
<table width="100%" border="0">
<tr>
<td>teadasdgads f</a></td>
</tr>
</table>
</td></tr>
<tr>
<td width="10" id="MyCell3"
onclick="ShowHi de('MyRow3','My Cell3')"><img
src="images/plus3.gif"></td>
<td width="205">bla hasdfadfadfasd</strong></a></div></td>
</tr>
<tr id="MyRow3">
<td>&nbsp;</td>
<td>
<table width="100%" border="0">
<tr>
<td>teadasdgads f</a></td>
</tr>
</table>
</td></tr>
</table>
<script type="text/javascript">
var m_intShow = 0;
function ShowHide(strRow ID,strCellID)
{
var objRow = document.getEle mentById(strRow ID);

if (m_intShow == 0)
{
objRow.style.di splay = "block";
var objCell = document.getEle mentById(strCel lID);
objCell.innerHT ML = "<img src=images/minus2.gif>";
m_intShow = 1;
}
else
{
objRow.style.di splay = "none";
var objCell = document.getEle mentById(strCel lID);
objCell.innerHT ML = "<img src=images/plus3.gif>";
m_intShow = 0;
};
}

function runhide(){
var objs = new Array();
rowCount = this.asdfform.t xtAID.value;
for(var i=1;i<=rowCount ;i++){
(objs[i] = document.getEle mentById("MyRow "+i)).style.dis play =
"none";
}
}

runhide()
</script>

So everything works really good on load up, it loads the rows in the
tables. When the table is done, the javascript loads runhide() which
collapses all of the rows.

The javascript works fine when they click on the plus and it shows the
row, and when I click on the same plus it collapses. The problem
is...when I click the first cell, it shows the row, then If I want to
expand cell 2, I have to click it twice to get it to expand. Then when
I go to cell 1, I have to click twice to collapse it.

If anyone can correct my coding it would be appreciated, thanks.

Sep 28 '05 #1
7 4903

Samir wrote:
[snip]
<script type="text/javascript">
var m_intShow = 0;
function ShowHide(strRow ID,strCellID)
{
var objRow = document.getEle mentById(strRow ID);

if (m_intShow == 0)
{
objRow.style.di splay = "block";
var objCell = document.getEle mentById(strCel lID);
objCell.innerHT ML = "<img src=images/minus2.gif>";
m_intShow = 1;
}
else
{
objRow.style.di splay = "none";
var objCell = document.getEle mentById(strCel lID);
objCell.innerHT ML = "<img src=images/plus3.gif>";
m_intShow = 0;
};
}

The problem is here. You have a logic error. You have a global
variable called m_intShow. Now consider the steps you just went
through:

step 1. The value of m_intShow is 0. You click on a +. The value of
m_intShow is now 1.

step 2. You click on a different +. The value of m_intShow is 1,
therefore the display is still set to "none". The value of m_intShow is
now 0.

step 3. You click on the same + again. The value of m_intShow is 0,
therefore the display will now be set to "block".

That is the reason why you have to click twice.

[snip] }
}

runhide()
</script>

So everything works really good on load up, it loads the rows in the
tables. When the table is done, the javascript loads runhide() which
collapses all of the rows.

The javascript works fine when they click on the plus and it shows the
row, and when I click on the same plus it collapses. The problem
is...when I click the first cell, it shows the row, then If I want to
expand cell 2, I have to click it twice to get it to expand. Then when
I go to cell 1, I have to click twice to collapse it.

If anyone can correct my coding it would be appreciated, thanks.


Sep 28 '05 #2
"Samir" <dl*****@yahoo. com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com...

[snip]

So everything works really good on load up, it loads the rows in the
tables. When the table is done, the javascript loads runhide() which
collapses all of the rows.

The javascript works fine when they click on the plus and it shows the
row, and when I click on the same plus it collapses. The problem
is...when I click the first cell, it shows the row, then If I want to
expand cell 2, I have to click it twice to get it to expand. Then when
I go to cell 1, I have to click twice to collapse it.

If anyone can correct my coding it would be appreciated, thanks.


This is a variation on your theme.
Test as-is. Watch for word-wrap.

<html>
<head>
<title>hideshow .htm</title>
<script type="text/javascript">
var a_intShow = new Array(0,0,0,0);
function ShowHide(intRow ID,intCellID) {
var objRow = document.getEle mentById("MyRow "+intRowID) ;
if (a_intShow[intRowID] == 0) {
objRow.style.di splay = "block";
var objCell = document.getEle mentById("MyCel l"+intCellID );
objCell.innerHT ML = "<img src='_minus.gif '>";
a_intShow[intRowID] = 1;
} else {
objRow.style.di splay = "none";
var objCell = document.getEle mentById("MyCel l"+intCellID );
objCell.innerHT ML = "<img src='_plus.gif' >";
a_intShow[intRowID] = 0;
}
}
function runhide() {
var objs = new Array();
rowCount = a_intShow.lengt h;
for (var i=1;i<rowCount; i++) {
objs[i] = document.getEle mentById("MyRow "+i).style.disp lay =
"none";
}
}
</script>
</head>
<body onload="runhide ()">
<table width="225" border="1">
<tr>
<td width="10" id="MyCell1" onclick="ShowHi de(1,1)"><img
src="_plus.gif" ></td>
<td width="205">bla hasdfadfadfasd> </td>
</tr>
<tr id="MyRow1">
<td>&nbsp;</td>
<td>
<table width="100%" border="0">
<tr>
<td>teadasdgads f</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="10" id="MyCell2" onclick="ShowHi de(2,2)"><img
src="_plus.gif" ></td>
<td width="205">bla hasdfadfadfasd</td>
</tr>
<tr id="MyRow2">
<td>&nbsp;</td>
<td>
<table width="100%" border="0">
<tr>
<td>teadasdgads f</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="10" id="MyCell3" onclick="ShowHi de(3,3)"><img
src="_plus.gif" ></td>
<td width="205">bla hasdfadfadfasd</td>
</tr>
<tr id="MyRow3">
<td>&nbsp;</td>
<td>
<table width="100%" border="0">
<tr>
<td>teadasdgads f</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
I changed the following:

1)
var a_intShow = new Array(0,0,0,0);
as added.

2)
rowCount = a_intShow.lengt h;
was
rowCount = this.asdfform.t xtAID.value;
as a form wasn't defined.

3)
objs[i] = document.getEle mentById("MyRow "+i).style.disp lay =
"none";
was
(objs[i] = document.getEle mentById("MyRow "+i)).style.dis play =
"none";
though I don't understand why you use "objs".

4)
<body onload="runhide ()">
was
runhide();
as the table wasn't declared before it was exceuted;
(at least after I moved the JS into the <head>).

I also removed a bunch of unnecessary
</strong></a></div>
and
</a.>
tags.
Sep 28 '05 #3
On 28/09/2005 20:39, Samir wrote:

[snipped markup]

Why you have so many tables I'll never know, but...

[snip]
objRow.style.di splay = "block";


....do not use the block value to 'show' rows or other table components.
Table-related elements have their own special display property values.
Using other values will break rendering behaviour in conforming browsers
(IE is broken in this regard).

Instead, assign an empty string to the display property. This
effectively clears the none value, showing the row in whatever way the
browser happens to expect.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Sep 28 '05 #4
McKirahan,

Thanks, The example I gave you, and you make it work perfect. I just
have one more question.

The reason I had rowCount = this.asdfform.t xtAID.value was I forgot
this was also in the page too
<form name="asdfform" >
<input type="text" name="txtAID" style="VISIBILI TY: hidden"
value="<%=strCo unt%>">
</form>

I did a count in ASP and tells me how many rows I have, so I can
collapse at the load page.

The javascript you gave me works perfect!! except when I use it in my
actual page, it works for the first 3 rows and the rest is working but
not like the first three rows.
Any where to write the array to account for the rowCountValue??

Thanks for all your help so far.

Sep 28 '05 #5
Okay I think I got it, took some thinking but it's working so far!!

rowCount = this.asdfform.t xtAID.value;
var a_intShow = new Array(rowCount) ;
for(var i=0;i<=rowCount ;i++){
a_intShow[i] = 0
}

What do you think?

Sep 28 '05 #6
Samir wrote:
McKirahan,

Thanks, The example I gave you, and you make it work perfect. I just
have one more question.

The reason I had rowCount = this.asdfform.t xtAID.value was I forgot
this was also in the page too
<form name="asdfform" >
<input type="text" name="txtAID" style="VISIBILI TY: hidden"
value="<%=strCo unt%>">
</form>

I did a count in ASP and tells me how many rows I have, so I can
collapse at the load page.
The number of rows in the table is given by the length of the table's
rows collection. You don't need the server to tell you how many there are.

var numberOfRows = someTableRef.ro ws.length;

The javascript you gave me works perfect!! except when I use it in my
actual page, it works for the first 3 rows and the rest is working but
not like the first three rows.
Any where to write the array to account for the rowCountValue??


You don't need to. All you need to do is show or hide cells that have
an index greater than zero in whatever row was clicked on. And the
hideShow function just needs to toggle between 'none' and ''.

That last bit is very important - the default value of a TD's display
attribute is not 'block', it is 'table-cell'. Since IE is broken in
this regard, you won't notice, but you will in other browsers.

<URL:http://www.w3.org/TR/REC-CSS2/tables.html#q5>

Switching between '' and 'none' allows it to return to whatever value
the browser likes without you having to know whether that was 'block' or
'table-cell' or some other value.

There have been several examples of how to do it posted in the last few
weeks, here's an example based on your posted code:

<table width="225" border="1" id="tableA">
<tr>
<td width="10"><img src="minus.gif"
onclick="showHi deCells(this)"> </td>
<td width="205">bla hasdfadfadfasd</strong></a></td>
</tr>
<tr>
<td width="10"><img src="minus.gif"
onclick="showHi deCells(this)"> </td>
<td width="205">bla hasdfadfadfasd</strong></a></td>
</tr>
<tr>
<td width="10"><img src="minus.gif"
onclick="showHi deCells(this)"> </td>
<td width="205">bla hasdfadfadfasd</strong></a></td>
</tr>
</table>
<script type="text/javascript">

function showHideCells( el )
{
// Change the image between + and -
if (el.src.match(' plus')){
el.src = el.src.replace(/plus/,'minus');
} else {
el.src = el.src.replace(/minus/,'plus');
}

// Find the parent td
while (el.parentNode && 'td' != el.nodeName.toL owerCase()){
el = el.parentNode;
}

// Run across all siblings and show/hide them
while (el.nextSibling ){
el = el.nextSibling;
if (el.style){
el.style.displa y = ('none' == el.style.displa y)? '' : 'none';
}
}
}

// Initially hide the cells using showHideCells()
function runHide(id)
{
if ( ! document.getEle mentById
|| ! document.getEle mentsByTagName
|| ! document.body.s tyle ) {
return;
}
var el = document.getEle mentById(id);
var rows = el.rows;
var i = rows.length;
while (i--){
showHideCells( rows[i].getElementsByT agName('img')[0]);
}
}

runHide('tableA ');

</script>

--
Rob
Sep 29 '05 #7
RobG,

Thanks for the replay, your coding seems to work but not really the way
I had the example.

Your coding shows the the 3 rows and shows the first cell of each row
and hides the 2nd cell until it is clicked.

What I am doing in the ASP page;

I do a query to a database table, say the table has data for company
and in this table I have over 50. and each company has a related table
which stores what products they have available, one company can have
one, and other have many, so I guess it's call a one to many.

I can write it to work on ASP but it involves the user to reload, I
figure javascript would be a lot more efficient in showing and hiding
the table rows.

So basically the code looks like this. I also added some code to show
and hide for onlclicks which kinda works.

<table width="225" border="0">
<%
'Show all accounts on load
strQ = ""
strQ = strQ & "SELECT * from comptbl where compid != '' Order By
compID"
'Execute query<br>
strCount = 0
Set oRS = objConn.Execute (strQ)
If not oRS.EOF then
Do While NOT oRS.EOF
strCount = strCount + 1
'View accounts
%>
<tr>
<td width="10" id="MyCell<%=st rCount%>"
onclick="ShowHi de('<%=strCount %>','<%=strCoun t%>')"><img
src="images/plus3.gif"></td>
<td width="205"><di v align="left"><s trong><a
href="Details.a sp?id=<%=oRS("c ompID")%>"
target="_main"> <%=oRS("compID" )%>
</strong></a></div></td>
</tr>
<tr id="MyRow<%=str Count%>">
<td>&nbsp;</td>
<td>
<%
sql = ""
rs = ""
sql = sql & "SELECT * from compProd where compID = '" & oRS("compID")
& "'"
sql = sql & " Order By name;"
Set rs = objConn.Execute (sql)
If not rs.EOF then
Do While NOT rs.EOF
%>
<table width="100%" border="0">
<tr>
<td><a href="Details.a sp?pid=<%=rs("c ompID")%>" target="_main">
<%=rs("pid")% >, <%=rs("pName")% ></a></td>
</tr>
</table>
<%
rs.MoveNext
Loop
rs.Close
Set rs=Nothing
End if
%>
</td></tr>
<%
oRS.MoveNext
Loop
oRS.Close
Set oRS = Nothing
End if
%>
</table>

<form name="asdfform" >
<input type="text" name="txtAID" style="VISIBILI TY: hidden"
value="<%=strCo untclients%>">

<script type="text/javascript">
rowCount = this.asdfform.t xtAID.value;
var a_intShow = new Array(rowCount) ;
for(var i=0;i<=rowCount ;i++){
a_intShow[i] = 0
}

function ShowHide(intRow ID,intCellID) {
var objRow = document.getEle mentById("MyRow "+intRowID) ;
if (a_intShow[intRowID] == 0) {
objRow.style.di splay = "block";
var objCell = document.getEle mentById("MyCel l"+intCellID );
objCell.innerHT ML = "<img src='images/minus2.gif'>";
a_intShow[intRowID] = 1;
} else {
objRow.style.di splay = "none";
var objCell = document.getEle mentById("MyCel l"+intCellID );
objCell.innerHT ML = "<img src='images/plus3.gif'>";
a_intShow[intRowID] = 0;
}
}

function runhide(){
var objs = new Array();
rowCount = this.asdfform.t xtAID.value;
for(var i=1;i<=rowCount ;i++){
(objs[i] =
document.getEle mentById("MyRow "+i)).style.dis play="none";
}
}

function showusers(){
var objs = new Array();
rowCount = this.asdfform.t xtAID.value;
for(var i=1;i<=rowCount ;i++){
(objs[i] =
document.getEle mentById("MyRow "+i)).style.dis play="block";
}
}

function showaccounts(){
var objs = new Array();
rowCount = this.asdfform.t xtAID.value;
for(var i=1;i<=rowCount ;i++){
(objs[i] =
document.getEle mentById("MyRow "+i)).style.dis play="none";
}
}
</script>

So if you have any suggestions that would be great!

Thanks.

Sep 29 '05 #8

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

Similar topics

3
29679
by: Jukka K. Korpela | last post by:
I have noticed that the meaning of visibility: collapse has been discussed on different forums, but with no consensus on what it really means. Besides, implementations differ. The specification says: "The 'visibility' property takes the value 'collapse' for row, row group, column, and column group elements. This value causes the entire row or column to be removed from the display, and the space normally taken up by the row or column to...
7
9319
by: Daniel Jung | last post by:
Hi ======== Problem: ======== I want images in table rows connect vertically. All images are 32 px in height. =====
3
1068
by: ireneatngs | last post by:
Hi, I have example html below which contains a couple of hidden divs. However, some of the table borders within these hidden divs are actually displayed when they should not be. In my example, I have comments indicating that if I remove the 'border-collapse' attribute for two of the tables within the hidden divs, my problem is fixed.
1
7549
by: Holmespundit | last post by:
Stylists... I'm having problems collapsing a column. Specifically, I want to collapse the last column of a table. My initial test with a large data set worked, but I cannot make it work with a small example. Here are links to the data files (source included below): http://home.covad.net/~holmespun/20050320_column_visibility_collapse_test.html http://home.covad.net/~holmespun/20050320_column_visibility_collapse_test.css
3
2755
by: Erwin Moller | last post by:
Hi all, Is it possible to collapse certain columns in a rendered table? I have been fiddling around with CSS and visibiliy: collapse, but I cannot get it working in NN6 and IE6 and firefox. What I want/tried is something like this: <STYLE TYPE="text/css"> TABLE {border-collapse: collapse;}
0
2365
by: invinfo | last post by:
I read some NG posts on this and also looked at W3C and others. http://www.w3.org/TR/CSS2/tables.html http://aerie.chirp.com.au/css/bordercollapse/ I could not make border-style: hidden work, next to <TD> with visible borders. I was successful using border-style: none if I used: border-collapse: separate
1
7616
by: Vaclav Jedlicka | last post by:
Hi I need a datagrid on a page, but it is rendered with the style "border-collapse:collapse;". I do not need this style. It interferes with the settings in my CSS file. I tried to supress it with this code (1 line of code): DataGrid1.ControlStyle.Reset(); which works.
4
3403
by: Gönen EREN | last post by:
how can i collapse or expand a node of treeview control programmaticly? thanks.
0
2557
by: Shadow Lynx | last post by:
When using ASP.NET 2.0's built-in TreeView on a page with <BASE target = "AnythingBut_Self"></BASE> in the HEAD, the expand/collapse buttons fail to function. The reason for this is that the hyperlinks generated for the expand/collapse buttons includes javascript code that will execute in the frame specified in the Base Target rather than the current document. To remedy this, TreeView should render a target="_self" attribute for each...
0
8987
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
8826
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
9534
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
9366
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...
1
9316
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
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...
0
4597
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...
1
3303
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 we have to send another system
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.