473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Swap Image and Unhide Text Not Working

I have a image that I want to click and when clicked that image will be
swapped and then show a hidden div. When another image like it is
clicked it will swap image and hide that text and so on. My problem is
that when I send the Image ID's to the function I cannot find a way to
insert the dynamic names. I thought I could get the ID and concate the
string to use in the function but if I do IM = "I"+id; and stick it in
IM.SRC = ... it will not work but if I debug the value of IM it is
correct. If I manually put in IM33.SRC = ... it works but will not
work with the contacted value. What am I doing wrong? Thanks

var previd;
function swapImage(id) {
var nid = "id_"+id;
var el = document.getElementById(nid);
alert("before"+id);
var im = 'I'+id;
alert("after"+im);
if(previd!=null)
{
alert("in here"+im)
previd.style.display="none";
im.src = "images/plussign.gif"
return(false);
}
alert("Original"+im+"EL="+el);
displayType = (el.style.display == "none")?"block":"none";
el.style.display = displayType;
previd=el;
im.src = "images/minussign.gif"
return(false);
}

Apr 20 '06 #1
2 1719
Barkster said the following on 4/19/2006 10:54 PM:
I have a image that I want to click and when clicked that image will be
swapped and then show a hidden div. When another image like it is
clicked it will swap image and hide that text and so on. My problem is
that when I send the Image ID's to the function I cannot find a way to
insert the dynamic names. I thought I could get the ID and concate the
string to use in the function but if I do IM = "I"+id; and stick it in
IM.SRC = ... it will not work but if I debug the value of IM it is
correct. If I manually put in IM33.SRC = ... it works but will not
work with the contacted value. What am I doing wrong? Thanks
<snip>
im.src = "images/plussign.gif"


Mistake #1: You are relying on IE's bad habit of making the ID of an
object a global variable pointing to that object
Mistake #2: Not using the images collection to access images.

document.images[im].src = "...";
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 20 '06 #2
Thanks for clearing that up for me. Thanks

Apr 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Richard | last post by:
Considering the elemtary image swap routine in javascript: document.name.src="filename.gif" How would this be translated into PHP? So that if a visitor has js turned off, clicking on a...
3
by: Randell D. | last post by:
Folks, I'm still learning javascript - I've invested in a couple of books and reading online as much as possible. I'm pretty sure what I am suggesting is possible though I'm trying to weigh up...
2
by: Matthew | last post by:
Hi all I'm looking for a solution that can be used in a calendar/gig guide scenario where each day is represented by a dot image. Now this dot must do the following 1. When the mouse goes...
6
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
4
by: bridgemanusa | last post by:
Hi All: I have a very long page of html that I want to take portions and hide them in divs, then show when a link is clicked. I have the hide show part working when the link is clicked, however...
6
by: Karl | last post by:
Hi, Ok so on a given page I have 4 text links: see it in black see it in blue see it in red see it in green using the standard swap image behavior, clicking on one of the above links
5
by: Ed Jay | last post by:
Why doesn't the following swap images? <head> <javascript type="text/javascript"> function swapImage() {document.images.image1.src=/images/1stimage.gif;} function swapBack()...
7
by: KiwiBrian | last post by:
On a web page I have a graphic for a Shopping Cart Submit button. It is within a form and working fine. I would like to perform an image swap to an identical graphic of a different colour when I...
2
by: sabbas | last post by:
Sorry for my bad english. this is my second web work and things are a little bit difficult for me, so sorry if you not understand what i want for this two situations. First one is that I have 3...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.