Click to See Complete Forum and Search --> : simple javascript any1?


tomas skersys
12-03-2002, 02:16 AM
i guess that should be pretty simple but i guess my knowledge on javascript is not enough in this case... anyways the main idea looks like this:
i have a index page with few links. all those links redirrect to the other page (with frames) on my site. and that framed page has one frame with the images corresponding to each link from the index page. How to make so that certain image in the frame of the loaded 2nd page is swapped from img1_inactive.gif to img1_active.gif when the certain link is pressed in the index page?? All other images keep the inactive form.

any ideas, pls?

p.s. and i'm not english so dont pick on my language style:D

Beach Bum
12-03-2002, 02:53 AM
I have a page just like that. Here is the script I use. This assumes that the name of the page is target and the image is named image1.

I first load a clear gif so the old image is replaced and image resize is not seen. Then I set the size for the new image. Then load the image. If you are not resizing the image each time then you only need the last line.

I have one function for each link.

function DisplayPic1() {
parent.target.document.image1.src = "clear.gif"
parent.target.document.image1.width = 500
parent.target.document.image1.height = 375
parent.target.document.image1.src = "second.jpg"
}

tomas skersys
12-03-2002, 08:37 AM
actually you could make one function for all images... just put a parameter into function's () and make a switch :)

too bad your source does not entirely solve my problem :(

the point is that i dont know how to detect the file's NAME where the FRAMESET is located... and the html file with the images recides in one of the FRAMES in that FRAMESET. And i need the file's name because that's the only way to find out what image your script should toggle...

to explain the situation more clearly... there are as many html files with FRAMESETs as links from the index page, but there's just one html file with the images and that file goes to ALL the files with the FRAMESETS. So the point is to detect in what file's FRAMESET that file with the images is being loaded to! Hope that helped ;)

Beach Bum
12-03-2002, 08:23 PM
I thought about putting a parameter in the function, but I decided it would be easier to maintain just copying the function. But as you said, that is not your issue.

. . . I have read and re-read your post. I just do not understand what you are trying to do. Can you give an example?

tomas skersys
12-04-2002, 03:58 AM
ok lets put some real names in here :)

1) i have index.htm with 3 links (lets name em link_1, link_2, link_3)

2) and i have 2nd_page.htm. This page has a frameset made of 3 frames. 1st frame has fr_1.htm in it, 2nd frame - fr_2.htm, 3rd frame - fr_3.htm.

3) fr_3.htm is the file with the images img1.gif, img2.gif, img3.gif!! (and other 2 frames arent important in this case)

4) now
4.1) when i clink on link_1 in the index.htm - it opens 2nd_page.htm AND there should be img1.gif switched to img1_active.gif in the fr_1.htm page.
4.2) when i clink on link_2 - it opens 2nd_page.htm AND there should be img2.gif switched to img2_active.gif in the fr_1.htm page.
4.3) when i clink on link_3 - it opens 2nd_page.htm AND there should be img3.gif switched to img3_active.gif in the fr_1.htm page.

of course i could make 3 different copies of fr_1.htm for each switched imgx.gif (just like u did with your function :)) but i'd love to avoid that :D

Beach Bum
12-04-2002, 02:24 PM
OK, what I think you told me -

You want to click a link (in your index page). You want that to do two things:

1) open a new page (which happens to contain a frameset).

2) you want to make in image in frame 1 or that frameset the same as an image that already is shown in frame 3 of that frameset.

so you want a script that opens a page on a link (in a new window?) and then that script needs to make a change to frame 1 in that frameset.

Assuming we are talking about opening a new window here (with your second page), then I don't know how you can do what you want to do - as the index page has no hierarchical relationship with the new window.

Now if instead of a new window you replaced an existing frame, that would be easy.

"of course i could make 3 different copies of fr_1.htm for each switched imgx.gif (just like u did with your function)"

I did not do that - I have the functions to avoid having a page for each image. That is the point of the function - so you do NOT need a page for each image. I do have one function per image (which I think is easier than doing it with one function and a passed parameter) but there is only one index page (that has the links and the functions) and one target page. The only reason I used frames for this is to have separate scrollable "sections" to the page (one for the index and one for the images).

so . . . if you could work your index page and your image pages into the one frameset, this would be easy.