Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

show 1 div hide another

Status
Not open for further replies.

JimJx

Technical User
Feb 16, 2001
202
US
Hi all,
what I am trying to do is when a user clicks on a button, show that div. I can get that to work. But, I also want to hide that button after it is clicked. That doesn't work and breaks the rest of the script so it doesn't work at all.....

The html for both examples is
Code:
<input style="display:all" id="update" type="button" value="Change Password" onclick="javascript:toggleLayer('frm1');" />
This works:
Code:
function toggleLayer(whichLayer)
{
if (document.getElementById)
{
// this is the way the standards work
var style2 = document.getElementById(whichLayer).style;
style2.display = style2.display? "":"block";
}
else if (document.all)
{
// this is the way old msie versions work
var style2 = document.all[whichLayer].style;
style2.display = style2.display? "":"block";
}
else if (document.layers)
{
// this is the way nn4 works
var style2 = document.layers[whichLayer].style;
style2.display = style2.display? "":"block";
}
}

This does not.....
Code:
function toggleLayer(whichLayer)
{
if (document.getElementById)
{
// this is the way the standards work
var style2 = document.getElementById(whichLayer).style;
var style3 = document.getElementById(update).style;
style2.display = style2.display? "":"block";
style3.display = style3.display? "":"block";
}
else if (document.all)
{
// this is the way old msie versions work
var style2 = document.all[whichLayer].style;
var style3 = document.all[update].style;
style2.display = style2.display? "":"block";
style3.display = style3.display? "":"block";
}
else if (document.layers)
{
// this is the way nn4 works
var style2 = document.layers[whichLayer].style;
var style3 = document.layers[update].style;
style2.display = style2.display? "":"block";
style3.display = style3.display? "":"block";
}
}

When I add the lines for style3, when I load the page, I get
Error in parsing value for property 'display.' Declaration dropped.
And when I click the button, I get the error
update is not defined

Any ideas about where I am going wrong?

Thanks!
Jim
 
1) get rid of the ghetto browser sniffing. it's so 90s. simply use document.getElementById - it works in most/all modern common browsers.

2) the update needs to be in quotes in [tt]var style3 = document.getElementById(update).style;[/tt]

3) i don't believe "all" is a valid display style setting.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Code:
<input style="display:[COLOR=red]block[/color]" id="update" type="button" value="Change Password" onclick="toggleLayer('frm1');" />

Then

Code:
function toggleLayer(id) {
document.getElelemtById(id).style.display = 'block';
document.getElelemtById('update').style.display = 'none';

... should do the trick!?
 
Thanks for the replies!

I went with the suggestion that I drop the sniffing and made a couple minor changes and everything works great now.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top