Jump to content

Toggle box need to clear variable


c_shelswell

Recommended Posts

Ok i think i'm getting closer to fixing my last problem. I have a much more simple bit of code that seems to mostly be doing the job. Though i still can't to clear the box after it's been clicked once.

Here's an example [url=http://www.alternatesource.co.uk]www.alternatesource.co.uk[/url] if you click "cut1" a box comes up that'll have a hyperlink in it. When you click "cut 2" it should be replaced by a new hyperlink but as you can see the old one remains there. I'm really not at all aufait with java spent most of last night learning about DOM to try and get my head round it  :)

my code is [code]<script type="text/javascript">

function toggleLayer(box, url)
{
var txtBox = document.getElementById(box);

if (txtBox.style.display != 'none')
{
txtBox.style.display = 'block';
var txt = document.createTextNode(url);
document.getElementById("box").appendChild(txt);
}
else
{
txtBox.style.display = 'none';
}
}

</script>
</head>

<body>
<br />
<div id="container">
<div id="box">
<!-- myBox -->
</div>

<div id="tableCont">
<table align="center" cellpadding="0" cellspacing="0" border="0">

<tr>

<td align="center" class="songBorder">
  <div class="TRtitle">Smokescreen</div>
  <a href="#" onClick="toggleLayer('box', 'num1');" class="cut">cut 1 </a>
  <a href="#" onClick="toggleLayer('box', 'num2');" class="cut">cut 2 </a>
  <br />
 
</td>
</tr>
</div>
[/code]

if anyone knows how i might sort this i'd be so grateful been stuck on it for a while now and im sure it's pretty easy.

Cheers
Link to comment
Share on other sites

no that doesn't seem to work i'm guessing i should be using removeChild somehow??

i've updated the code a little

[code]
function toggleLayer(url)
{  
var txtBox = document.getElementById('box');

var newLink=document.createElement('a');
newLink.setAttribute('href', url);
newLink.className='dl';

var linkText=document.createTextNode('Download');
newLink.appendChild(linkText);


if (txtBox.style.display != 'none')
{
txtBox.style.display = 'block';
document.getElementById('box').appendChild(newLink);
}
else
{
txtBox.style.display = 'none';
}
}[/code]

but still can't get that on/off toggle i'm after getting very frustrated wish i knew more about javascript
Link to comment
Share on other sites

yeah i tried that on the revised code but it seems to stop the text from displaying as a hyperlink.

I've put an example up at www.alternatesource.co.uk it's cut1 and cut2 under smokescreen that i've currently got linked up. Will give you an idea of hows it's working.

Thanks for the help
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.