Forum Moderators: open

Message Too Old, No Replies

Changing Images From A Value

         

civilhorseman

3:14 am on Dec 31, 2007 (gmt 0)

10+ Year Member



Could someone please help me with my problem? I am fairly new to javascript and I can’t get the script to run right! My page is running tables, and I require a link from the bottom table to change an image in the top table. I was able to make this work using the following code:

function changeImage(){var img = parent.frames[0].document.getElementById("Image2");
img.setAttribute("src","www.MyWebSite.com/Images/0001.gif")}

The problem I am having NOW, is that I have another link on the bottom table, that must first retrieve a value from the top table which creates part of the href for the image, which then changes the image again in the top table. The code I am trying to work with is:

function changeImage1(){var na = parent.frames[0].document.getElementById("Field1").value;
document.getElementsByTagName('a')[0].href='www.MyWebSite.com/Images/'+na;}

OK... This code will retrieve the value fine and creates the new href too! But it loads the new image in the bottom table and not back in the top table! I’m pretty sure all I need to do is add: parent.frames[0] to the bottom line of the code to send the image back to the top, but I have been playing around with this, with no luck! Could someone PLEASE Help me...........

Also as a secondary problem which may arise later. Apart from just sending it back to the top table, Is it possible to replace the old image (in my “Image2”) with the new Image created with the value?

daveVk

5:10 am on Dec 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Based on original code of changeImage

function changeImage1(){
var na = parent.frames[0].document.getElementById("Field1").value;
var img = parent.frames[0].document.getElementById("Image2");
img.setAttribute("src","www.MyWebSite.com/Images/" + na)
}