Logged Out
Create an Account
Login:
Password:

Forgot your password?
Javascript help

Javascript help
[Back to Index]
Thread Tags
Primary: [Advanced Layout]
Secondary: None

Ok I have IDs on my elements, and I have script that hides some of them. Do when I run that script I pass the ID of the object to the script. What I would like to do is set Boolean variables that track if the object is visible or not. So I have a table with the ID of myTable. I would like to have a boolean variable named bolmyTable.

How do I address the variable bolmyTable if I know that the myTable is the ID and it is stored in variable item_id?

"bol" + item_id ?


--
Eleipher, The Warlock Extraordinaire
The New Beginning
Thorium Brother Hood



Guild Webmaster
I'm not sure, to be honest, but I'd advise a more concise methodology for this.

The property style.display can contain the pertinent information.


So you could do something like

if(document.getElementById("elementid").style.display == "none")
{
//do what you want if the object is hidden
}
else
{
//do what you want if the object is visible
}



--
It's all in the reflexes.
I tried that, but to get things to work properly, I had to initially set the display to none. It seems to me that no matter what it's current state, it returns the display as none.

I have to check that again, as I may well have made a mistake in coding when I was testing that.

I am just learning javascript.


--
Eleipher, The Warlock Extraordinaire
The New Beginning
Thorium Brother Hood



Guild Webmaster
Quote by carlpalmer
I tried that, but to get things to work properly, I had to initially set the display to none. It seems to me that no matter what it's current state, it returns the display as none.

I have to check that again, as I may well have made a mistake in coding when I was testing that.

I am just learning javascript.


Why don't you paste your function, as well as the Element with the ID that you want to show hide... it will help us debug your code. As it stands, Chops example should work perfectly.

Let me play with it, and if it isn't working for me, I will toss some code out here. It may take a while with kara coming up for the next few days.


--
Eleipher, The Warlock Extraordinaire
The New Beginning
Thorium Brother Hood



Guild Webmaster
I did something similar on my guild's site, only I went the route of manually deciding when to show or hide the menu, then give users the ability to show or hide it.

It sounds to me more like you'll have to set cookies for the state of the div/table for that user, and check against that. If the cookie doesn't exist, you make it and set everything to visible (or not visible) initially.
That way, the cookie remembers that user's setting for whatever you're showing or hiding.


Now, if you want to go the route of showing or hiding certain items based on what page is showing (that's what I did on my site) then you'll have to find some way to check the page you're on, then hide/show the element as needed.


--
. : Keela
Designer of www.renewal-guild.com
I want to do pretty much exactly that. Define variables, initialize them on startup, and then use them during the session, and write them when the user leaves. I have always never used javascript before, and I trying to figure out how to best do this.


--
Eleipher, The Warlock Extraordinaire
The New Beginning
Thorium Brother Hood



Guild Webmaster
You're probably going to want to use javascript cookies.


--
It's all in the reflexes.


[Back to Index]