c_shelswell Posted January 31, 2007 Share Posted January 31, 2007 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 Quote Link to comment Share on other sites More sharing options...
paul2463 Posted January 31, 2007 Share Posted January 31, 2007 could you not put the follwing line in before you set the new appendchild()[code]document.getElementById("box").value = "";[/code] Quote Link to comment Share on other sites More sharing options...
c_shelswell Posted February 1, 2007 Author Share Posted February 1, 2007 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 Quote Link to comment Share on other sites More sharing options...
bibby Posted February 1, 2007 Share Posted February 1, 2007 what about :-\[code]document.getElementById("box").innerHTML=txt;[/code] Quote Link to comment Share on other sites More sharing options...
c_shelswell Posted February 1, 2007 Author Share Posted February 1, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.