www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] my images keep dissapearing?? please help

Hybrid View

  1. #1
    Join Date
    Oct 2010
    Posts
    6

    resolved [RESOLVED] my images keep dissapearing?? please help

    Okay so I've been working on simple button click selector/slideshow such as what you see on nbc.com for a school project. It HAS to be in plain jane javascript. I got the button selection thing working, but whenever I click one of the buttons.. the image flashes in the "content area" (an image inside an anchor tag that will change depending on which button has been pressed) and then just goes back to the default image (the source inside the original image tag). Please help. I'm kind of a novice at javascript and for the life of me I have no idea why the image isn't staying in that dang thing. I tried it without having to click on a button, just calling the function right after defining it and passing the variables and works just fine, which has me even more confused.

    Here's the code:
    Code:
    <script type="text/javascript">
    <!--
    //create image array
    	var tt=new Array("assets/ww.jpg","assets/discussion.gif","assets/officeSpaceSmall.jpg","assets/projects.jpg");
    
    	function changeit(imgname,imgsrc) 
    	{	
    	document[imgname].src= imgsrc;
    	}
    //-->	
    </script>
    
    
    <div class="tips">
    	<ul>
    	<li>
    		<a href="" id="l1" onclick="changeit('pic',tt[0]);"><h6>tutoring</h6></a>
    	</li>
    	<li>
    		<a href="" id="l2" onclick="changeit('pic',tt[1]);"><h6>discussions</h6></a>
    	</li>
    	<li>
    		<a href="" id="l3" onclick="changeit('pic',tt[2]);"><h6>workshops</h6></a>
    	</li>
    	<li>
    		<a href="" id="l4" onclick="changeit('pic',tt[3]);"><h6>projects</h6></a>
    	</li>
    	</ul>
    	
    	<div>
    	<a href=""><img src="assets/ww.jpg" name="pic" width="400" height="258" /></a>
    	</div>
    </div>

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    The natural anchor event fires (reload) after completing the function call. Prevent this with return false:
    Code:
    <a href="" id="l1" onclick="changeit('pic',tt[0]);return false;"><h6>tutoring</h6></a>
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Oct 2010
    Posts
    6

    Thank you thank you!!!!

    I forgot about that! Now to get the scrolling working :-) I'm going to try to execute a loop on the array...

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    At least 98% of internet users' DNA is identical to that of chimpanzees

  5. #5
    Join Date
    Oct 2010
    Posts
    6

    Question not sure that I follow

    The w3c article appears to be talking about ids and names (id="",name=""). I don't have any strictly numeric ids (id='l1' etc is found). The only numeric identifiers that would be used would be for the array index [0,1,2, ...]

    It appears that that would be a valid sgml type for an array. Am I mistaken? Were you just giving me a heads up? Please explain. I definitely want to understand.

  6. #6
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Sorry my mistake, the 'l' looks like a '1' in my editor
    At least 98% of internet users' DNA is identical to that of chimpanzees

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles