• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Problem with if..else..

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
When my page loads the <div>content is hidden, which is what I want, but I have to click on the link twice to make it appear. I would prefer to click only once to make the <div>content appear.
I think the problem is in the loop, but I have not been able to figure it out. The code is below. Any help would be appreciated.
Thanks
Thom
<HEAD>
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
var action = true;
function display(name) {
if (document.all) {
var layerObj = eval("document.all." + name + ".style");
var hide = "hidden";
var show = "visible";
}
else {
var layerObj = eval("document." + name);
var hide = "hide";
var show = "show";
}
layerObj.visibility = (action ? hide : show);
action = !action;
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<DIV ID="test_1" STYLE="position:relative;background-color:#cccccc;width:200;visibility:hidden">
Yes it is <a href="test_2.html">click</a>.
</DIV>
<p>Is this a sample question? 
<a href="javascript:display('test_1');">Click to test</a>
</p>
</BODY>
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it will work just the way you want if you initialize 'action' to false, instead of true.
 
Thom Spencer
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Chris...it works!
I had originally tried that before I added visibility:hidden but not after.
Thom
 
reply
    Bookmark Topic Watch Topic
  • New Topic