473,320 Members | 1,977 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,320 software developers and data experts.

Equating an Image Object to another does not give the desired result, plz help.

Hi there, I just found these forums and several questions I had have been answered by just reading the posts but this one.

I have simplified my code in order to just get to the point with my question.
This is my html code:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. </head>
  4. <body>
  5.  
  6.  <img id="img1" src="images/smile.jpg" style="border:#0000FF solid 2px;"/>
  7.  
  8.  <script language="javascript">
  9.  
  10.    my_image = new Image;
  11.    my_image.src="images/sad.jpg"; my_image.style.border="#FFFFFF solid 5px";
  12.  
  13.    x=document.getElementById("img1");
  14.    x=my_image;
  15.  </script>
  16.  
  17. </body>
  18. </html>
  19.  
Before I set "x=my_image", the x object is referring to the image object within the document, so far so good. After the assignment, x is referring to the my_image object and now there is no relationship at all with the image within the document. What I want to accomplish is for the image object within the document to be referring to the my_image object so it updates all of the properties I pre-set for my_image(which will be several in my real code). How can I do that?, or is it best to remove the image object and then append the new my_image to the document(or to the container that will hold it)?

I want to do an image slicing within an html document so I would be updating that object with different images and properties through an adequate set of controls and javascript events of course, this code is just the idea to present my problem.
Jul 9 '08 #1
3 1213
mrhoo
428 256MB
The Image object is not an html element. It does have a src property, which you can read and apply to an img element.


my_image = new Image();
my_image.src="images/sad.jpg";

document.getElementById("img1").src= my_image.src;
Jul 9 '08 #2
rnd me
427 Expert 256MB
The Image object is not an html element.

dont want to be a wise-guy, but i think you might be wrong:

Expand|Select|Wrap|Line Numbers
  1. var i = new Image(100,100);
  2.  
  3. alert(i.constructor) // "HTMLImageElement"
  4.  
  5. //  also it can be appended just like any other element:
  6.  
  7. i.src="http://bytes.com/forum/customavatars/avatar117351_1.gif";
  8. document.body.appendChild(i)
  9.  
  10.  
Jul 9 '08 #3
rnd me
427 Expert 256MB

What I want to accomplish is for the image object within the document to be referring to the my_image object so it updates all of the properties I pre-set for my_image(which will be several in my real code). How can I do that?, or is it best to remove the image object and then append the new my_image to the document(or to the container that will hold it)?

I want to do an image slicing within an html document so I would be updating that object with different images and properties through an adequate set of controls and javascript events of course, this code is just the idea to present my problem.

>> How can I do that?, : you can't. once its in the dom, you have to use dom MPEs to alter it in a way that changes appear.


>> or is it best to remove the image object and then append the new my_image to the document(or to the container that will hold it)? : thats what i would do, or perhaps give the tag a id, and put all of your images inside the container, img.style.display="none".
then simply 1. hide all of them. 2. show the one you need. to change the image.
Jul 9 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: lawrence | last post by:
So far I've got the code you see below. I've not yet figured out how to change the name of the file. I'm creating several images of different sizes. I need to give them all different names. How do...
1
by: Wayne's World | last post by:
hi everyone, i have a big problem, writing a image from my applet to my apache webserver. i tried three way's of writing that file. every way was described in forums to solve this problem, but...
14
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
15
by: Anand Ganesh | last post by:
HI All, I have an Image. I want to clip a portion of it and copy to another image. How to do this? I know the bounding rectangle to clip. Any suggestions please. Thanks for your time and...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
5
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: ...
31
by: Martin Clark | last post by:
Hello, I am daring to stick my head above the parapet and ask as question. I am working on redesigning a website to use CSS rather than tables for layout. I have come across a problem when trying...
9
by: kombu67 | last post by:
I'm reading a series of images from a MS SQL table and saving them to directory. These are staff ID pictures from our security card app. Once I've extracted the ID photo from the security app to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.