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

question about checking the status of a style

I've got the following script that toggles the visibility of a <form>
from Display: none, to Display: Block. Works great. But when I try to
first run a check like:

function show(id){

var el = document.getElementById(id);

if(el.style.display == 'none'){

el.style.display = 'visible';

}
else
{
el.style.display = 'none';
}

}

it doesn't work. The CSS and HTML is below:

The CSS looks like this:

#myform {
display: none;
}
The html looks like this:

<div id="login">
<h1><a href="#" onclick="show('myform')">Login</a></h1>
</div>
<div id="loginform">
<form id="myform" name="login">
UserName: <input name="username" type="text" size="15" /><br />
PassWord: <input name="" type="password" />
</form>
</div>

I admit to total newbieness so I'm still in the learning curve. I've
googled various things but haven't been able to figure this out. Thanks
again in advance.

greg g.
Jul 4 '06 #1
1 1328
gerg wrote:
I've got the following script that toggles the visibility of a <form>
from Display: none, to Display: Block. Works great. But when I try to
first run a check like:

function show(id){

var el = document.getElementById(id);

if(el.style.display == 'none'){

el.style.display = 'visible';

}
else
{
el.style.display = 'none';
}

}

it doesn't work. The CSS and HTML is below:
The style object represents the style applied to an element either in
line (in the HTML) or by script, it doesn't show what has been set by
inheritance or style sheet or whatever.

The usual method is to toggle the display property between 'none' and
''. "Visible" is not a valid value for the display property:

<URL:http://www.w3.org/TR/CSS21/propidx.html>

try:

function show(id)
{
var el = document.getElementById(id);

if (el && el.style){
el.style.display = ('none' == el.style.display)? '' : 'none';
}
}

You need feature detection for getElementById too, but you may have done
that elsewhere.

The CSS looks like this:

#myform {
display: none;
}
It's not a good idea to rely on script making things visible, if it's
disabled or not available, and CSS is, the user will never see the
hidden element.

[...]
I admit to total newbieness so I'm still in the learning curve. I've
googled various things but haven't been able to figure this out. Thanks
again in advance.
Search the archives, it's been posted many, many times. :-)

Here's one from less than 2 weeks ago, search for "display none toggle":

<URL:http://groups.google.com.au/group/comp.lang.javascript/browse_frm/thread/1d52bbd06184cb4/68dadf4e4057887b?q=style.display+none&rnum=5#68dad f4e4057887b>
--
Rob
Jul 4 '06 #2

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

Similar topics

2
by: George Sakkis | last post by:
I downloaded the latest Komodo (3.1) and configured it for python 2.4 so that it doesn't show decorators and genexps as syntax errors, but background syntax checking doesn't seem to work at all for...
38
by: Shaun McKinnon | last post by:
HI...Here's my problem...I have a popup window that loads when i want it to, but it's not sized properly. I've set the size, but it doesn't seem to work. I've been on 8 different websites to find...
16
by: John | last post by:
I found this code for the site I'm working on (www.sovietposters.tk). It does exactly what I want but I can't figure out how to change the color of the tabs. Anyone any suggestions? John ...
16
by: dario | last post by:
Hi, Im new on phyton programming. On my GPRS modem with embedded Phyton 1.5.2+ version, I have to receive a string from serial port and after send this one enclosed in an e-mail. All OK if the...
3
by: windandwaves | last post by:
Hi Gurus Does anyone know how I set the error trapping to option 2 in visual basic. I know that you can go to tools, options and then choose on unhandled errors only, but is there a VB command...
30
by: Michael B Allen | last post by:
I have a general purpose library that has a lot of checks for bad input parameters like: void * linkedlist_get(struct linkedlist *l, unsigned int idx) { if (l == NULL) { errno = EINVAL;...
2
by: Robert Smith jr. | last post by:
Hello, Please pardon my newbie question ... I am building an ASP.NET page that displays a recordset with a Delete statement enabled (this all works fine). I want to Insert the current row...
10
by: e_matthes | last post by:
Hello everyone, I have read many threads about concurrency issues, and I think I understand some of the pieces, but not the whole picture. I believe I am like many people using php: ...
0
by: tvnaidu | last post by:
I wrote a status page HTML code, here I have 8 port status, it prints first 7 and last status it won't print, from there onwards it won't print footer also, if I make 10 instead 8, then it prints...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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: 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...

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.