473,769 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getEle mentById(nid);
alert("before"+ id);
var im = 'I'+id;
alert("after"+i m);
if(previd!=null )
{
alert("in here"+im)
previd.style.di splay="none";
im.src = "images/plussign.gif"
return(false);
}
alert("Original "+im+"EL="+ el);
displayType = (el.style.displ ay == "none")?"block" :"none";
el.style.displa y = displayType;
previd=el;
im.src = "images/minussign.gif"
return(false);
}

Apr 20 '06 #1
2 1745
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.javas cript 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
1861
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 thumbnail would show the larger image.
3
6166
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 the faults that might go with the suggestion... all opinions welcome. My question: I have a list of links that go to pages that have a similar layout. Could I have a text swap, similar to what I've seen with image swaps (or an image switch)...
2
1889
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 over the dot image it swaps to the mouseover dot 2. When the mouse goes out of the dot image it restores back to the original img 3. When the img is clicked the dot image is swapped with another image
6
13024
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 is not an ASP.NET related question, but I know this group is knowledgeable and quick with responses. Thanks
4
4232
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 I would really like to use linked images instead to do the following: - When open.gif is clicked, the contents of the div show and open.gif is swapped with close.gif - subsequently, when close.gif is clicked, the div contents get hidden
6
3197
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
2796
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() {document.images.image1.src=/images/2ndimage.gif;} </script> </head><body> <a href=url onMouseOver=swapImage(); onMouseOut=swapBack();>
7
8297
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 hover over the button. Can anyone show me how to do this, or point me to an implementation. My present code for the submit button is:- <input type="image" name="submit" src="images/addtocart1.gif"> This changes the cursor to a hand, and operates...
2
1979
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 links made by 3 small images. (e.g the links are: videos, music, pics) These links upload 3 different .html pages in the same iframe depends on which link you click. What i want is when you make a click with mouse on the first link e.g.(videos) i want...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10219
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.