473,588 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hide/unhide script for dyanamic table

Hi everyone,

I have found and addapted a script that displays or hides a div tag
based on it's current class tag, but i can't seem to get it to work. I
am new to Java, and i know that everything has to be perfect in order
for it to function.

Would it be possible for someone to check over my script and point out
any errors there may be/extra spaces etc?

Here is the script:

function Toggle(id)
{
if(document.get ElementById("de tails" + id).class == 'hide')
{
document.getEle mentById("detai ls" + id").class='blu e_sub_body_exp' ;
document.images["expand" + id].src= "colapse.gi f";
}

else
{
document.getEle mentById("detai ls" + id).class='hide ';
document.images["expand" + id].src= "expand.gif ";
}

}

Thanks, i appologise if it's something glaringly obvious.

Gavin

Feb 3 '07 #1
3 5706
Daz
On Feb 3, 10:13 pm, "Gavin" <GJPeac...@gmai l.comwrote:
Hi everyone,

I have found and addapted a script that displays or hides a div tag
based on it's current class tag, but i can't seem to get it to work. I
am new to Java, and i know that everything has to be perfect in order
for it to function.
I Gavin. First of all it's 'JavaScript', not Java. It's a common
misconception that the wo are related, when they actually aren't.
>
Would it be possible for someone to check over my script and point out
any errors there may be/extra spaces etc?
I can't see any errors in your script, but I am not an expert. Are you
getting any errors? I recommend you install Firefox, and use the
JavaScript debugger which will tell you if anything is wrong. I
suspect that you might not be calling on the function properly. Can
you post an example of the actual page that contains the onclick
function trigger?
>
Here is the script:

function Toggle(id)
{
if(document.get ElementById("de tails" + id).class == 'hide')
{
document.getEle mentById("detai ls" + id").class='blu e_sub_body_exp' ;
document.images["expand" + id].src= "colapse.gi f";

}

else
{
document.getEle mentById("detai ls" + id).class='hide ';
document.images["expand" + id].src= "expand.gif ";

}
}

Thanks, i appologise if it's something glaringly obvious.

Gavin

Feb 3 '07 #2
Gavin wrote:
Hi everyone,

I have found and addapted a script that displays or hides a div tag
based on it's current class tag, but i can't seem to get it to work. I
am new to Java,
Javascript is not Java. :-)
and i know that everything has to be perfect in order
for it to function.

Would it be possible for someone to check over my script and point out
any errors there may be/extra spaces etc?

Here is the script:

function Toggle(id)
It's a common convention that function names starting with an uppercase
letter are constructors. Better in this case to use a lower case "t".

{
if(document.get ElementById("de tails" + id).class == 'hide')
Since "class" is a future reserved word in ECMAScript ed 3 (and likely
to be used if JavaScript 2.0 aka ECMAScript ed 4 is ever released) the
CSS class property is called "className" .

It is also prudent to check that the value returned by getElementById
before attempting to access its class property:

function toggle(id) {
var el = document.getEle mentById("detai ls" + id);
if (el && el.className == 'hide') {
...

{
document.getEle mentById("detai ls" + id").class='blu e_sub_body_exp' ;
If you store the returned value of the getElementById, then you don't
have to call it again.

el.className = 'blue_sub_body_ exp';

document.images["expand" + id].src= "colapse.gi f";
You can probably change the image too as a property of the CSS class
applied to the div - look at using a positioned background image with no
repeat, then when you change the class of the div, the image changes
too. Then your toggle function becomes:

function toggle(id) {
var el = document.getEle mentById("detai ls" + id);
if (el) {
el.className = (el.className== 'hide')? 'blue_sub_body_ exp':'hide';
}
}
--
Rob
Feb 4 '07 #3
Daz
On Feb 4, 1:30 am, RobG <r...@iinet.net .auwrote:
Gavin wrote:
Hi everyone,
I have found and addapted a script that displays or hides a div tag
based on it's current class tag, but i can't seem to get it to work. I
am new to Java,

Javascript is not Java. :-)
and i know that everything has to be perfect in order
for it to function.
Would it be possible for someone to check over my script and point out
any errors there may be/extra spaces etc?
Here is the script:
function Toggle(id)

It's a common convention that function names starting with an uppercase
letter are constructors. Better in this case to use a lower case "t".
{
if(document.get ElementById("de tails" + id).class == 'hide')

Since "class" is a future reserved word in ECMAScript ed 3 (and likely
to be used if JavaScript 2.0 aka ECMAScript ed 4 is ever released) the
CSS class property is called "className" .

It is also prudent to check that the value returned by getElementById
before attempting to access its class property:

function toggle(id) {
var el = document.getEle mentById("detai ls" + id);
if (el && el.className == 'hide') {
...
{
document.getEle mentById("detai ls" + id").class='blu e_sub_body_exp' ;

If you store the returned value of the getElementById, then you don't
have to call it again.

el.className = 'blue_sub_body_ exp';
document.images["expand" + id].src= "colapse.gi f";

You can probably change the image too as a property of the CSS class
applied to the div - look at using a positioned background image with no
repeat, then when you change the class of the div, the image changes
too. Then your toggle function becomes:

function toggle(id) {
var el = document.getEle mentById("detai ls" + id);
if (el) {
el.className = (el.className== 'hide')? 'blue_sub_body_ exp':'hide';
}

}

--
Rob
Doh! It's className not class. How did I miss that...? I think my
skills of observation have a lot to be desired.

Feb 4 '07 #4

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

Similar topics

9
33426
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 between BLOCK and NONE. This technique works on normal text fine, but it doesn't work on part of the table, is there a solution that I can achieve the goal of turning on/off several rows all together? Thanks.
5
4768
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" : "none"); }
2
2209
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 = false). However, when I have the bottom one in that column to be the one to be used
3
2788
by: toodi4 | last post by:
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...
3
2429
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 modal form and editing the record. I would like the user to be able to hide either the parent form or the parent and modal form if they are currently editing in the modal form and unhide the parent or both forms from the notification icon. I seem...
1
5771
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.
7
5085
by: cefrancke | last post by:
I have a few tables with sensitive user information (passwords, etc.) and I would like to prevent someone from opening a blank database and importing those tables. Is there a way to "hide" or protect these tables from being linked or imported? TIA
4
3062
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 same as in xml file plz give me the answer with example any body knows. <html> <head> <title>CB Hide/Show</title> <script type="text/javascript"> <!-- function showMe (it, box) { var vis = (box.checked) ? "block" : "none";...
6
3946
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 am starting on a new project which is part library so I think it would be good to hide the implementation for the public classes in the library but this seems a lot of overhead to me (both when developing and runtime overhead).
0
7929
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
7862
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,...
1
7987
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
8223
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
6634
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5398
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3847
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
2372
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
0
1196
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.