Toggle Image - Problem in IE

K

kiran

Hi All

I am using the below function to change an image. I have checked in IE
and its working properly if seen locally on my system.

If the same is inserted in a jsp file and accessed from server, image
is toggled but it is not visible.

If we right click on the image and select 'Show Picture' it is
displayed.
Weird IE problem!!!! Anyone has solutions for this.

Kiran Makam


function toggleImg(name){
var obj = document.images[name];
var src = obj.src.toLowerCase();

if(src.indexOf("yes") != -1){
obj.src = "images/no.gif";
obj.alt = "Collapse";
}else{
obj.src = "images/yes.gif";
obj.alt = "Expand";
}
}
 
V

Vincent van Beveren

Thats weird,

I don't know why it goes wrong, but maybe preloading the images might
help. In the header, put the following code:

<SCRIPT LANGUAGE="JavaScript">
imYes = new Image();
imYes.src = 'images/yes.gif';
imNo = new Image();
imNo.src = 'images/no.gif';
</SCRIPT>

You're sure those images are the correct filenames? Did you check for
upper & lowcase? might be sensetive to that.
 
K

kiran

Thanks Beveren.

I have preloaded the images, still the problem persists. I checked
browser cache after the page is loaded, preloading is working fine.

If i try the function in a static page on my system, it works; when it
is added to a jsp file and accessed from server images refuses to show
up!!!!!

Kiran
 
V

Vincent van Beveren

If i try the function in a static page on my system, it works; when it
is added to a jsp file and accessed from server images refuses to show
up!!!!!

I have no idea. Sorry. It should indeed work.
 
G

Grant Wagner

kiran said:
Thanks Beveren.

I have preloaded the images, still the problem persists. I checked
browser cache after the page is loaded, preloading is working fine.

If i try the function in a static page on my system, it works; when it
is added to a jsp file and accessed from server images refuses to show
up!!!!!

Kiran

Check the source the browser is seeing. It's most likely that when the JSP
outputs the client-side JavaScript, you are losing quotation marks
somewhere along the way.

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top