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

Home Posts Topics Members FAQ

Accessing Image in Another <Div>

Hi,

I am just a javascript beginner so maybe this is a simple problem but I
am trying to do some rollovers on images in a separate <div>. Here is
the relevent piece of my code:

<html>
<head>
<script type="text/javascript">
if (document.image s) {
a_1 = new Image;
a_1.src = "DesignedImages \header.jpg";

b_1 = new Image;
b_1.src = "DesignedImages \line6.jpg";
}

function showImg(imgname , rollname)
{
var obja = parent.document .getElementById ("roll_a");
var objb = parent.document .getElementById ("roll_b");
if (document.image s) {
window.onerror = null;
document.getEle mentById(rollna me).src=eval(im gname +
".src");
}
}
</script>
</head>
<body>
<div id="topOrganize r">
<div id="top" align="center">
<img src="DesignedIm ages\header.jpg " id="roll_a">
</div>
<div id="line1">
<img src="DesignedIm ages\line5.jpg" id="roll_b">
</div>
</div>
<div id="header">
<div id="links">
<ul id="rolllist">
<li><a href="Peterson. html"
onmouseover="sh owImg('a_1','ob ja');showImg('b _1','objb')"><b >REPRESENTATI VE
PROJECTS</b></a>&nbsp;&nbsp;< img src="DesignedIm ages/button.jpg"></li>
</ul>
</div>
</body>

Due to the rather complicated nature of the design I really want to
keep using divs rather than a table but I really need to get the
rollover to work as well. I just keep getting an error that it can't
find the image object.

Can anyone help me?

Thanks!

Joy

Oct 30 '06 #1
7 2461
ASM
si***********@y ahoo.com a écrit :
Hi,

I am just a javascript beginner so maybe this is a simple problem but I
am trying to do some rollovers on images in a separate <div>. Here is
the relevent piece of my code:
To roll-over images is very easy, you just need they are named

<script type="text/javascript">
function change() {
old2 = document.i_2.sr c;
old1 = document.i_1.sr c;
document.i_1.sr c = document.i_1.sr c==old1? old2 : old1;
document.i_2.sr c = document.i_2.sr c==old2? old1 : old2;
}
</script>
<div>
<img src="asm1.gif" name="i_1" onclick="change ();">
</div>
<div>
<img src="asm2.gif" name="i_2" onclick="change ();">
</div>
<form>
<input type=button value=change onclick="change ();">
</form>

or :

<script type="text/javascript">
function exchange(img1,i mg2) {
img1 = eval('document. '+img1)
img2 = eval('document. '+img2)
old2 = img2.src;
old1 = img1.src;
img1.src = img1.src==old1? old2 : old1;
img2.src = img2.src==old2? old1 : old2;
}
</script>
<div>
<img src="asm1.gif" name="i_1" onclick="exchan ge('i_1', 'i_2');">
</div>
<div>
<img src="asm2.gif" name="i_2" onclick="exchan ge('i_1', 'i_2');">
</div>
<form>
<input type=button value=exchange onclick="exchan ge('i_1', 'i_2');">
</form>
Tested : FireFox, Safari, Opera 9, IE 5.2 Mac, NC4.5
(NC.4 needs a button, onclick on images gives nothing)

The complete very old method for rollOvers in JS :

<script type="text/javascript">
if(document.ima ges) {
img1 = new Image(); img1.src = 'asm1.gif';
img2 = new Image(); img2.src = 'asm2.gif';
}
function roll(name, imag) {
if(document.ima ges {
eval('document. images["'+name+'"].src = '+imag+'.src');
}
}
</script>
<divExample 1 (one image rolled) :
<img src="asm1.gif" name="i_1"
onmouseover="ro ll('i_1','img2' )"
onmouseout=" roll('i_1','img 1')">
</div>
<divExample 1 (two images rolled) :
<img src="asm2.gif" name="i_2"
onmouseover="ro ll('i_1','img2' );roll('i_2','i mg1')"
onmouseout=" roll('i_1','img 1');roll('i_2', 'img2')">
</div>

<html>
<head>
<script type="text/javascript">
if (document.image s) {
a_1 = new Image;
a_1.src = "DesignedImages \header.jpg";

b_1 = new Image;
b_1.src = "DesignedImages \line6.jpg";
}
function showImg(imgname , rollname)
{
var obja = parent.document .getElementById ("roll_a");
var objb = parent.document .getElementById ("roll_b");
if (document.image s) {
window.onerror = null;
document.getEle mentById(rollna me).src=eval(im gname +
".src");
}
}
function showImg(imgname , rollname){
if (document.image s) {
document.getEle mentById(rollna me).src = eval(imgname+'. src');
}
}
</script>
</head>
<body>
<div id="topOrganize r">
<div id="top" align="center">
<img src="DesignedIm ages\header.jpg " id="roll_a">
</div>
<div id="line1">
<img src="DesignedIm ages\line5.jpg" id="roll_b">
</div>
</div>
<div id="header">
<div id="links">
<ul id="rolllist">
<li><a href="Peterson. html"
onmouseover="sh owImg('a_1','ob ja');showImg('b _1','objb')"><b >REPRESENTATI VE
PROJECTS</b></a>&nbsp;&nbsp;< img src="DesignedIm ages/button.jpg"></li>
<a href="Peterson. html"
onmouseover="sh owImg('a_1','ro ll_a'); showImg('b_1',' roll_b')"
><b>REPRESENTAT IVE PROJECTS</b>
</a>
</ul>
</div>
</body>

Due to the rather complicated nature of the design I really want to
keep using divs rather than a table but I really need to get the
rollover to work as well. I just keep getting an error that it can't
find the image object.
of course : you don't give name of the object !
Oct 30 '06 #2

ASM wrote:
si***********@y ahoo.com a écrit :
Hi,

I am just a javascript beginner so maybe this is a simple problem but I
am trying to do some rollovers on images in a separate <div>. Here is
the relevent piece of my code:

To roll-over images is very easy, you just need they are named
CSS rollovers are considerably simpler, very few new sites use scripted
rollovers:

<URL: http://alistapart.com/stories/rollovers/ >

Of course the OP may just be doing this for practice. :-)

[...]

--
Rob

Oct 30 '06 #3
ASM
RobG a écrit :
ASM wrote:
>si***********@y ahoo.com a écrit :
>>Hi,

I am just a javascript beginner so maybe this is a simple problem but I
am trying to do some rollovers on images in a separate <div>. Here is
the relevent piece of my code:
To roll-over images is very easy, you just need they are named

CSS rollovers are considerably simpler, very few new sites use scripted
rollovers:
Ho yes ! I forgot to tell him.

But to roll over another image than this mouseoverized ...
and much more better to keep it changed ...
perhaps with css5 ?

A very interresting site about all kind of overizations on images via css :
http://www.cssplay.co.uk/menu/index.html
and my prefered (I find very clever) :
- FireFox only
http://www.cssplay.co.uk/menu/superanimation.html
- Panoramic image scroller
http://www.cssplay.co.uk/menu/scroller.html

--
ASM
Oct 30 '06 #4
Thank you but all that doesn't actually answer my question. I know how
to rollover images when you hover over the image itself - but I want to
do a rollover of an image when you hover over a link that is in a
different <div>. I found code that shows how to do a rollover on an
image when you hover over a link but the code doesn't work if the image
and link are in two separate <div>s you see??

Is there any solution for this problem?

Thanks!

Oct 31 '06 #5
si***********@y ahoo.com <si***********@ yahoo.comwrote:
>
Is there any solution for this problem?
yes sure are links and images of the same number ?
--
Une Bévue
Oct 31 '06 #6

si***********@y ahoo.com wrote:
Thank you but all that doesn't actually answer my question. I know how
to rollover images when you hover over the image itself - but I want to
do a rollover of an image when you hover over a link that is in a
different <div>.
The theory is exactly the same - use onmouseover to change the src
attribute of some image. Where it is in the document is irrelevant
(unless it's in an iFrame under some conditions).

I found code that shows how to do a rollover on an
image when you hover over a link but the code doesn't work if the image
and link are in two separate <div>s you see??
I can't see what you don't post.

Is there any solution for this problem?
Thousands.

Go to the Google news site: <URL:
http://news.google.com/news?ned=au&topic=t download some of their
thumbnails and save them as a.jpg, b.jpg, etc. then try the following:

<title>Image Rollover Play</title>
<script type="text/javascript">

function swapImg(el){
document.images['mainImg'].src = el.src;
}

</script>
<div style="float:le ft; border:1px solid blue;">
<img src="a.jpg" onmouseover="sw apImg(this);">< br>
<img src="b.jpg" onmouseover="sw apImg(this);">< br>
<img src="c.jpg" onmouseover="sw apImg(this);">< br>
<img src="d.jpg" onmouseover="sw apImg(this);">< br>
</div>
<div style="margin-left: 160px;">
<img src="a.jpg" name="mainImg">
</div>
--
Rob

Oct 31 '06 #7
ASM
si***********@y ahoo.com a écrit :
Thank you but all that doesn't actually answer my question.
To who do you speak ?
I know how
to rollover images when you hover over the image itself -
Bravissimo.
but I want to
do a rollover of an image when you hover over a link that is in a
different <div>. I found code that shows how to do a rollover on an
image when you hover over a link but the code doesn't work if the image
and link are in two separate <div>s you see??
I did see ... and did give you several solutions
Is there any solution for this problem?
I did have corrected your script ...

But perhaps do you prefer to spend your time to ask without reading
answers ?

--
ASM
Oct 31 '06 #8

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

Similar topics

1
2509
by: Philo | last post by:
How do I select all <div> tags except those which contain a <table> tag somewhere within them? Example XML: <********************** sample input ***********************> <txtSectionBody> <div> <span>
8
14467
by: Daniel Hansen | last post by:
I know this must seem totally basic and stupid, but I cannot find any reference that describes how to control the spacing between <p>...</p> and <div>...</div> blocks. When I implement these on a page, there is a huge gap (like 3/8 inch or 25 px) between them. This is driving me bananas. What the hey am I missing? dh ------------------------------------------------ Dan Hansen ------------------------------------------------
6
37153
by: Marcus Otmarsen | last post by:
Ok, the situation is as follows: I defined a <DIV> like: <div id="myid" style="position: absolute; height: 10; width: 10;"><img src="images/object.gif" height=10 width=10></div> This pane is used to move an object around on the web page by a javascript. As long as I define no further <div> pane everything works fine.
4
7236
by: Tim Sheets | last post by:
Hi all, I am having a problem that seems so simple, I am almost embarrassed to ask about it. I am working on a page that has the layout largely css driven. The top of the page has two <img> tags, one a logo, the other a graphic just for looks. If I use the following code: <div id="header">
3
3812
by: Josef K. | last post by:
Asp.net generates the following html when producing RadioButton lists: <td><input id="RadioButtonList_3" type="radio" name="MyRadioButtonList" value="644" onclick="__doPostBack('SitesRadioButtonList_3','')" language="javascript" />
0
359
by: tomasio | last post by:
Dear NG-Readers, First I want to apologize for crossposting this, but I got no idea where this topic really belongs to. I have built a html-page with some CSS. Anything behaves as expected, just the two images inside the <div> with the class attributes "schraffur-bottom" and "content-bottom" appear 10px below their corresponding containers. As the two pics are 10px high in total, I think it has something to do with the images. Anybody...
4
4359
by: ontheplains | last post by:
so i need to use a mouseOver on a piece of text that is in one <div> (says "Show Me the Alternate") to make a <div> tag that has content in it move from its current spot (left: 20%), to out of the frame to the left (like left: -100%). at the same time, i need to have the <div> that was already at left: -100% move to the spot of the other, at left: 20%. i also need to be able to mouseOver another piece of text ("Go Back to the Original") and...
8
609
by: CJM | last post by:
I've inserted a new banner in an existing page and I want the banner image to be centered (horizontally) within its container. I'm not bothered whether the accompanying line of text is restricted to the width of the image and centered, or whether is simply fills the width of the container. I've tried various things to achieve this (e.g setting margins to auto) but I'm not having much luck. The URL for the page is: http://www.eminox.es
8
10047
prino
by: prino | last post by:
Hi all, I've written code (in REXX) that takes files in legacy languages (PL/I, COBOL, z/OS assembler, etc) and converts them into HTML in a format similar to what's displayed in the z/OS ISPF editor. A fellow member of the PCG has helped me by creating a bit of Javascript to emulate the scrolling and using Google I've now gotten it into a state where it almost passes the W3C Markup Validation Service. However, the one error, Error Line 166,...
0
10039
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
9990
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
9860
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...
0
8869
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...
0
6668
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
5297
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
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.