SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Toggling box on and off

    Hi i'm really stuck with a problem and if someone could help i'd be so grateful. I've been doing php for a bit but at the moment javascript is a little lost on me.

    I'm basically trying to make a toggle box that when a user clicks on one link it brings up a box with an url in it when they click on a different link a new url pops up.

    Here's an example www.alternatesource.co.uk if you click Smokescreen "cut1" a box comes up with 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.

    Here's my code
    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';
    	}
    }
    if anyone could help that'd be great

    Thanks

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try changing this:
    Code:
    txtBox.style.display = 'block';
    document.getElementById('box').appendChild(newLink);
    to this:
    Edit:


    Code:
    txtBox.style.display = 'block';
    txtBox.innerHTML = "";
    txtBox.appendChild(newLink);
    Last edited by 7stud; Feb 2, 2007 at 01:15.

  3. #3
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I owe you a very big drink!!! Thank you that's been a real problem for me for a few days.

    Very frustrating as i knew i should be simple
    Cheers!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •