PDA

View Full Version : Help with changing multiple images


CyberScout
10-18-2002, 01:09 PM
I am using a FileTree on a website that uses "function showhide" and changes images depending on if they have clicked there before.

Below is the script that runs everything. The problem comes up when I add a "what6" to the "function showhide." if I am only using up to "what5" then it works fine.

Basically it gives me an error telling me the this line:
"what6.src=button_03b.src" is 'undefinded' is null or not a defined object

as well as this line
"what6.src=button_03.src"

Any help with this would be greatly appreciated.

Thanks in advance

<script language="javascript">
<!--
var Open = ""
var Closed = ""

function preload(){
if(document.images){
Open = new Image
Closed = new Image
button_02b = new Image
button_02 = new Image
large_01b = new Image
large_01 = new Image
small_01b = new Image
small_01 = new Image
button_03b = new Image
button_03 = new Image
Open.src = "open.gif"
Closed.src = "closed.gif"
button_02b.src = "images/leftnav/button_02b.gif"
button_02.src = "images/leftnav/button_02.gif"
large_01b.src = "images/tones/large_01b.gif"
large_01.src = "images/tones/large_01.gif"
small_01b.src = "images/tones/small_01b.gif"
small_01.src = "images/tones/small_01.gif"
button_03b.src = "images/leftnav/button_03b.gif"
button_03.src = "images/leftnav/button_03.gif"
}}


function showhide(what,what2,what3,what4,what5,what6){
if (what.style.display=='none'){
what.style.display='';
what2.src=Open.src
what3.src=button_02b.src
what4.src=large_01b.src
what5.src=small_01b.src
what6.src=button_03b.src
}
else{
what.style.display='none'
what2.src=Closed.src
what3.src=button_02.src
what4.src=large_01.src
what5.src=small_01.src
what6.src=button_03.src
}
}
//-->
</script>

Mr J
10-18-2002, 02:34 PM
Hmmm.......... not too sure about your script, try this one.

Just change the images to suit etc.




<script language="JavaScript">
var Images = new Array("on.gif","off.gif","on2.gif","off2.gif") // list images to preload
var preloadImages=new Array() // preloads images
for (i=0;i<=Images.length-1;i++) {
preloadImages[i]=new Image()
preloadImages[i].src=Images[i]
}

LastID = ""

function ON(id){
(LastID != id?document[id].src = "yourimageon.gif":"")
}

function OFF(id){
(LastID != id?document[id].src = "yourimageoff.gif":"")
}

// -->
</script>

<a href="yourpage.htm" onMouseOver="ON('image1');" onMouseOut="OFF('image1')">
<img src="yourimage.gif" border="0" name="image1">Link One</a>

<a href="yourpage.htm" onMouseOver="ON('image2');" onMouseOut="OFF('image2')">
<img src="yourimage.gif" border="0" name="image2">Link Two</a>

CyberScout
10-18-2002, 02:38 PM
Problem is this script is part of a filetree that can be seen at http://www2.hfs.psu.edu/traveltest/

and the images need to change on a click, not on a mouseover/mouseout

Mr J
10-18-2002, 07:56 PM
In the following function you have six arguments

function showhide(what,what2,what3,what4,what5,what6)

yet in all the function calls you are only passing 5 arguments and referencing 6 in the script.



showhide(menu1outline,menu1sign,menu1button,menu1large,menu1small)


Removing argument 'what6'

and the following lines

what6.src=button_03b.src

from the if/else statement allows the script to function as it should without any errors.


I think

See how it goes, let me know

CyberScout
10-18-2002, 08:02 PM
Well, the question is ... How do I continue the script so when they get to Menu2 they will be activating what6?

Mr J
10-18-2002, 08:23 PM
Hmm......


Ok .... keep the 'what6' argument in, but replace the lines


what6.src=button_03b.src


With



if(what6==null){
return
}
else{
what6.src=button_03b.src
}


See if that helps

CyberScout
10-18-2002, 08:34 PM
Oh man .... we are SO CLOSE!

I reposted what it is doing now. http://www.hfs.psu.edu/traveltest

As you can see the errors are gone, but now the images don't match up when they change. The second button turns to the first and the third turns to the first and so on.

This is what keeps getting me stumped.

I think I need to seperate something but I am not sure what.

Thanks for getting me to this point though.

Any help after this would be GREAT!

CyberScout
10-18-2002, 08:39 PM
Whoops .. the URL is

http://www2.hfs.psu.edu/traveltest

Mr J
10-18-2002, 10:43 PM
You have only replaced one

what6.src=button_03b.src

with

if(what6==null){
return
}
else{
what6.src=button_03b.src
}

The function should be as follows

function showhide(what,what2,what3,what4,what5,what6){
if (what.style.display=='none'){
what.style.display='';
what2.src=Open.src
what3.src=button_02b.src
what4.src=large_01b.src
what5.src=small_01b.src
if(what6==null){
return
}
else{
what6.src=button_03b.src
}
}
else{
what.style.display='none'
what2.src=Closed.src
what3.src=button_02.src
what4.src=large_01.src
what5.src=small_01.src
if(what6==null){
return
}
else{
what6.src=button_03b.src
}
}
}



You have to remember I am working without images here so I cannot see the results


BUT ................. you got me puzzled now


Why the two different urls with one working and one not?

And two totally different scripts?

CyberScout
10-24-2002, 01:22 PM
Mr J

You rock ... you got me much further then I would have been. I finally did figure it out, so thanks for the push in the right direction.

-CyberScout