473,692 Members | 2,747 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 1734
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
1856
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
6155
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
1885
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
12999
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
4222
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
3190
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
2786
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
8294
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
1970
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
8549
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
9094
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...
1
8814
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
7642
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6468
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
5823
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4332
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2244
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.