473,385 Members | 1,740 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,385 software developers and data experts.

hide/unhide data with variable numbers of fields

I'm using a javascript that hides and unhides text based on a button
click. It works great across static fields on a form. The problem I
have is that I'm trying to hide and unhide various fields that are
populated on the page by a database. In other words, sometimes there
are 4 fields, sometimes 6.

I've used various scripts for the hide/unhide function. This is one
I'm using now that I've copied from another source:

<script language = "Javascript">

var isIE=document.all?true:false;
var isDOM=document.getElementById?true:false;
var isNS4=document.layers?true:false;
function toggleT(_w,_h) {
if (isDOM)
{
if (_h=='s')
document.getElementById(_w).style.visibility='visi ble';
if (_h=='h') document.getElementById(_w).style.visibility='hidd en';
}
else if (isIE) {
if (_h=='s')
eval("document.all."+_w+".style.visibility='visibl e';");
if (_h=='h')
eval("document.all."+_w+".style.visibility='hidden ';");
}
else if(isNS4)
{
if (_h=='s') eval("document.layers['"+_w+"'].visibility='show';");
if (_h=='h') eval("document.layers['"+_w+"'].visibility='hide';");
}
}
</script>
So if in the button field I have onclick =toggleT('divt1','s');
toggleT('divt2','s'); then it will work for spans with id divt1 and
divt2.

If I place the <spantag in front of one of the dynamic fields, then
the same value id=divt shows for each field displayed, so it only works
with the first field with that id. I've tried widening the span beyond
the field so that the span won't be repeated, but it doesn't seem to
work. I'm not sure what the restrictions are regarding how wide a span
can be or what can be enclosed within it.

I'm obviously not a javascript expert, and perhaps the above script is
not the best one to use for my purposes. But I'm sure this issue must
arise a lot and I just don't know how to address it.

Thanks for your help.

Nov 17 '06 #1
3 2777
toodi4 wrote on 17 nov 2006 in comp.lang.javascript:
I'm using a javascript that hides and unhides text based on a button
click. It works great across static fields on a form. The problem I
have is that I'm trying to hide and unhide various fields that are
populated on the page by a database. In other words, sometimes there
are 4 fields, sometimes 6.

I've used various scripts for the hide/unhide function. This is one
I'm using now that I've copied from another source:

<script language = "Javascript">
<script type='text/javascript'>
>
var isIE=document.all?true:false;
var isDOM=document.getElementById?true:false;
var isNS4=document.layers?true:false;
This is ancient code!!!

document.getElementById() is nearly universal nowadays.
function toggleT(_w,_h) {
if (isDOM)
{
if (_h=='s')
document.getElementById(_w).style.visibility='visi ble';
if (_h=='h') document.getElementById(_w).style.visibility='hidd en';
}
else if (isIE) {
if (_h=='s')
eval("document.all."+_w+".style.visibility='visibl e';");
Do not use eval(), it is evil, dangerous, and not necessary
if (_h=='h')
eval("document.all."+_w+".style.visibility='hidden ';");
}
else if(isNS4)
{
if (_h=='s') eval("document.layers['"+_w+"'].visibility='show';");
if (_h=='h') eval("document.layers['"+_w+"'].visibility='hide';");
}
}
</script>
So if in the button field I have onclick =toggleT('divt1','s');
toggleT('divt2','s'); then it will work for spans with id divt1 and
divt2.
Why not change the <spantagName collection elements in a <div>
with css style?

====================================
<script type='text/javascript'>

function hideshow(x){
var spandiv = document.getElementById('spandiv')
var spanGroup = spandiv.getElementsByTagName('SPAN')
for(i=0;i<spanGroup.length;i++)
spanGroup[i].style.visibility=(x=='hide')?'hidden':'visible'
}

</script>

<div id='spandiv'>
<span>111111</span>
===
<span>222222</span>
===
<span>333333</span>
===
<span>444444</span>
===
<span>555555</span>
</div>
<br><br>
<button onclick='hideshow("hide")'>hide</button>
<button onclick='hideshow("show")'>show</button>
============================================

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Nov 17 '06 #2
Daz

Evertjan. wrote:
toodi4 wrote on 17 nov 2006 in comp.lang.javascript:
I'm using a javascript that hides and unhides text based on a button
click. It works great across static fields on a form. The problem I
have is that I'm trying to hide and unhide various fields that are
populated on the page by a database. In other words, sometimes there
are 4 fields, sometimes 6.

I've used various scripts for the hide/unhide function. This is one
I'm using now that I've copied from another source:

<script language = "Javascript">

<script type='text/javascript'>

var isIE=document.all?true:false;
var isDOM=document.getElementById?true:false;
var isNS4=document.layers?true:false;

This is ancient code!!!

document.getElementById() is nearly universal nowadays.
function toggleT(_w,_h) {
if (isDOM)
{
if (_h=='s')
document.getElementById(_w).style.visibility='visi ble';
if (_h=='h') document.getElementById(_w).style.visibility='hidd en';
}
else if (isIE) {
if (_h=='s')
eval("document.all."+_w+".style.visibility='visibl e';");

Do not use eval(), it is evil, dangerous, and not necessary
if (_h=='h')
eval("document.all."+_w+".style.visibility='hidden ';");
}
else if(isNS4)
{
if (_h=='s') eval("document.layers['"+_w+"'].visibility='show';");
if (_h=='h') eval("document.layers['"+_w+"'].visibility='hide';");
}
}
</script>
So if in the button field I have onclick =toggleT('divt1','s');
toggleT('divt2','s'); then it will work for spans with id divt1 and
divt2.

Why not change the <spantagName collection elements in a <div>
with css style?

====================================
<script type='text/javascript'>

function hideshow(x){
var spandiv = document.getElementById('spandiv')
var spanGroup = spandiv.getElementsByTagName('SPAN')
for(i=0;i<spanGroup.length;i++)
spanGroup[i].style.visibility=(x=='hide')?'hidden':'visible'
}

</script>

<div id='spandiv'>
<span>111111</span>
===
<span>222222</span>
===
<span>333333</span>
===
<span>444444</span>
===
<span>555555</span>
</div>
<br><br>
<button onclick='hideshow("hide")'>hide</button>
<button onclick='hideshow("show")'>show</button>
============================================

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
I think that what Evertjan may be hinting at, is that you may need to
create a class, that will create 'objects' on-the-fly containing a dive
element, which contains all of your span elements, and also the
appropriate link/button(s) to show and hide that particular div element.

Nov 18 '06 #3
Daz

Daz wrote:
I think that what Evertjan may be hinting at, is that you may need to
create a class, that will create 'objects' on-the-fly containing a dive
element, which contains all of your span elements, and also the
appropriate link/button(s) to show and hide that particular div element.
CORRECTION:
'dive' should be read as 'div'.

Nov 18 '06 #4

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

Similar topics

12
by: deko | last post by:
Is there any way to work around the blank space created by hidden divs? I'm trying to use a relatively postioned divs with show/hide behaviors to annotate an image. The divs show/hide...
9
by: Wang, Jay | last post by:
I try to group several rows in a table into a div and show/hide them by click on a button somewhere with a javascript link. When clicked, the link will toggle the style of the div section's style...
5
by: mooeypoo | last post by:
Hello all, I'm a php developer. I have been using a very simple script to hide/unhide divs in my script: function DisplayI(obj) { obj.style.display=("none"==obj.style.display? "block" :...
2
by: | last post by:
I have a page where I have 3 combo boxes listed in a column. sort of like: combo1 combo2 combo3 Based on which one is clicked, the others are supposed to hide (i.e. combobox.visible =...
1
by: Simon | last post by:
Dear reader, In a form with the property "Default view" as DataSheet I like to hide some fields in the datasheet view. It is possible to manage this with the command Format>>Unhide...
3
by: =?Utf-8?B?aWxy?= | last post by:
Hi All I am developing an vb 2005 winforms application that connects to a database and displays a datagridview of the data. A user can select and then edit, or create a new entry by opening a...
1
by: Simon | last post by:
Dear reader, In a datasheet form you have the possibility to hide or unhide columns. But in case the datasheet form is a sub-form this functionality is not longer available.
4
by: somasekhar | last post by:
Does anyone know how to have a user click a checkbox to unhide a editfield Unclick of the checkbox would hide it again. There is an example of html file on the Javascript .But I want hide and unhide...
6
by: Ralph | last post by:
Hi, I was reading effictive C++ and some other books again and they all tell you about hiding implementation details (proxy/pimpl/inheritance) but they never really explain when to use it. I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.