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
https://forums.phpfreaks.com/topic/36463-toggle-box-need-to-clear-variable/
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
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.