Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Can't get a div window to show!
Old 03-27-2007, 12:34 AM Can't get a div window to show!
amox's Avatar
Novice Talker

Posts: 10
Name: Nash Field
Trades: 0
Hi,
A div window containing an image appears when loaded and will hide after 3 seconds. It also has a close link for users who can't wait. I have created a link to have it appear again. However, when I clicked on the link, the window does not appear! This bug appears when I let the first div window closes by itself using a setTimeout. However, if i voluntarily closes, I can always click the link to have it appear again. Why so?

Here's my HTML code:

Code:
<body>
<script language="javascript">
    setTimeout('displayTeaser()',3000);
</script>
<div id="teaser" style="display: block; width:575px; height:300px; position:absolute; left: 16px; top: 105px;" >
<table border="0" width="575" cellpadding="0" cellspacing="0">
<tr>
    <td height="20" align="center">
        <div id="closer">
             <strong><a href="javascript:closeTeaser()">[x] Close This Ad</a>
             </strong>
       </div>
    </td>
</tr>
<tr>
    <td><img src="myimage.jpg" /></td>
</tr>
</table>
</div>
<p>Click <a href="javascript:displayAgain()">here</a> to display image again.</p>
</body>
Here's my javascript:
Code:
function displayTeaser(){
    var e=document.getElementById("teaser");
    if(e.style.display=='block'){
        e.style.display = 'none';
        e.style.visibility = 'hidden';
    }
}

function displayAgain(){
    var ee=document.getElementById("teaser");
    if(ee.style.display=='none'){
        ee.style.display='block';
        alert("i'm here!");
    }
}

function closeTeaser(){
    var f=document.getElementById("teaser");
    if(f.style.display=='block')
        f.style.display='none';
}
amox is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-27-2007, 12:34 PM Re: Can't get a div window to show!
RikComery's Avatar
Average Talker

Posts: 18
Location: Essex, United Kingdom
Trades: 0
I haven't looked too deeply into your code. However, i notice you have three functions that effectively do the same thing.... Show or hide a div.

This simplified script uses only one function and should work fine.

HTML Code:
<html>
<head>
<script type="text/javascript">
function showHideTeaser(){
  var e=document.getElementById("teaser");
  if(e.style.display == 'block'){
    e.style.display = 'none';
  } else {
    e.style.display = 'block';
  }
}

window.onload = function(){
  setTimeout('showHideTeaser()',3000);
}
</script>
</head>

<body>
<body>

<div id="teaser" style="display: block; width:575px; height:300px; position:absolute; left: 16px; top: 105px;" >
  <table border="0" width="575" cellpadding="0" cellspacing="0">
    <tr>
      <td height="20" align="center">
        <div id="closer">
          <strong><a href="javascript:showHideTeaser()">[x] Close This Ad</a></strong>
        </div>
      </td>
    </tr>
    <tr>
      <td><img src="myimage.jpg" /></td>
    </tr>
  </table>
</div>
<p>Click <a href="javascript:showHideTeaser()">here</a> to display image again.</p>
</body>
</body>
</html>
RikComery is offline
Reply With Quote
View Public Profile Visit RikComery's homepage!
 
Old 03-28-2007, 11:48 PM Re: Can't get a div window to show!
amox's Avatar
Novice Talker

Posts: 10
Name: Nash Field
Trades: 0
Wow that works! Thanks!
amox is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Can't get a div window to show!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11147 seconds with 12 queries