473,799 Members | 3,121 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Showwing an image from a variable?

If I have a variable named 'fred', the contents looking like this:
'/gif/picture1.gif', how can I display that image?

Thanks!

Ross

Jul 20 '05 #1
6 30643
"Ross M. Greenberg" <gr******@catsk ill.net> writes:
If I have a variable named 'fred', the contents looking like this:
'/gif/picture1.gif', how can I display that image?


Where?

You can do this:
---
var img = new Image();
img.src=fred;
document.body.a ppendChild(img) ;
---
but that displays the image at the end of the document.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
"Lasse Reichstein Nielsen" <lr*@hotpop.com > wrote in message
news:3c******** **@hotpop.com.. .
<snip>
You can do this:
---
var img = new Image();
img.src=fred;
document.body.a ppendChild(img) ;
---
but that displays the image at the end of the document.


On some of the more recent browsers new Image() is very like
document.create Element('img') and does return an object with all of the
characteristics of an IMG element. But they are not required to be
equivalent, and I don't think I would recommend new Image() over
createElement (if available, so probably whenever appendChild is
available (except for possible problems with IE 4 and late Opera 6
versions [1])). On IceBrowser, for example, creating and appending an
IMG element will work but the global Image constructor is a functionless
dummy.

Richard.

[1] For reasons that have never become clear Opera 6 (at least the later
versions) has a document.create Element function, but as it is not
possible to dynamically alter the DOM in the browser on Opera 6 there
doesn't seem much point in having the function (and I don't think that
it is functional). IE 4 has both document.create Element and appendChild
methods on its elements but they are pre-W3C DOM methods and cannot be
used in the same way as the W3C versions.
Jul 20 '05 #3
The variable "fred" is defined in the HEAD, and as such is static for the life
of the rendering.

I want a tag such as <IMG src=fred...>, but I simply don't know the proper
syntax for such.

Newbie question I know, but then I are one...

Thanks!

Ross
"Lasse Reichstein Nielsen" <lr*@hotpop.com > wrote in message
news:3c******** **@hotpop.com.. .
"Ross M. Greenberg" <gr******@catsk ill.net> writes:
If I have a variable named 'fred', the contents looking like this:
'/gif/picture1.gif', how can I display that image?


Where?

You can do this:
---
var img = new Image();
img.src=fred;
document.body.a ppendChild(img) ;
---
but that displays the image at the end of the document.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'


Jul 20 '05 #4
"Ross M. Greenberg" <gr******@catsk ill.net> writes:

Please don't top-post.
The variable "fred" is defined in the HEAD, and as such is static
for the life of the rendering.

I want a tag such as <IMG src=fred...>, but I simply don't know the proper
syntax for such.


Where do you want it?

What you can do is to add
<script type="text/javascript">
document.write( "<img src=\""+fred+"\ " ... >");
</script>

That will add an image tag where the script tag is.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
<head>
<script type="javascrip t">
var fred = 'path/to/image.jpg';
</script>
</head>
<body>
<script type="text/javascript">
document.write( '<img src="' + fred + '" />');
</script>
</body>

Of course if the user doesn't have client-side JavaScript enabled, they get
nothing. I better alternative might be:

<head>
<script type="javascrip t">
var fred = 'path/to/image.jpg';
</script>
</head>
<body onload="
if (document.image s && document.images['myImage']) {
document.images['myImage'].src = fred;
}
">
<img name="myImage" src="/path/to/dummyImage.jpg" />
</body>
"Ross M. Greenberg" wrote:
The variable "fred" is defined in the HEAD, and as such is static for the life
of the rendering.

I want a tag such as <IMG src=fred...>, but I simply don't know the proper
syntax for such.

Newbie question I know, but then I are one...

Thanks!

Ross
"Lasse Reichstein Nielsen" <lr*@hotpop.com > wrote in message
news:3c******** **@hotpop.com.. .
"Ross M. Greenberg" <gr******@catsk ill.net> writes:
If I have a variable named 'fred', the contents looking like this:
'/gif/picture1.gif', how can I display that image?


Where?

You can do this:
---
var img = new Image();
img.src=fred;
document.body.a ppendChild(img) ;
---
but that displays the image at the end of the document.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'


--
| Grant Wagner <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #6
Lasse Reichstein Nielsen hu kiteb:
"Ross M. Greenberg" <gr******@catsk ill.net> writes:

Please don't top-post.
The variable "fred" is defined in the HEAD, and as such is static
for the life of the rendering.

I want a tag such as <IMG src=fred...>, but I simply don't know the
proper syntax for such.


Where do you want it?

What you can do is to add
<script type="text/javascript">
document.write( "<img src=\""+fred+"\ " ... >");
</script>

That will add an image tag where the script tag is.


Yet another methodf is:

document.getEle mentById(id).sr c = fred;

Where you have an ID attribute on the image.

--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk
Jul 20 '05 #7

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

Similar topics

9
3146
by: Shapper | last post by:
Hello, I am declaring a variable in my aspx.vb code as follows: Public Class catalogue Public productid As String Private Sub Page_Load ... I have an image button where I call the following function:
3
1148
by: jcrouse | last post by:
How do you empty the contents of a variable the contains an image? Thank you, John
1
2499
by: Tufty | last post by:
Hi, I have a webpage that lets the user upload an image. This is the posted to a perl script as a form var. The data is stored in SQL 2005 (as the new image object). I now need to get it back out from SQL and display it in an HTML page being generated by perl. I can read the data back in, but can't get it to display. (typically it justs says ) when I refere to the perl variable. Has anyone ANY experience / ideas on how to do this?...
3
9224
by: Peter | last post by:
..NET 2.0 I have an Image on my form and I am trying to clear this image and re-load it with different image. Everything works fine, but once I load the image I can not delete this image until I close the program. How can I clear the image so I can delete it. Here's my code: string imgFileName = @"C:\myImage.jpg";
1
1971
by: spgedwards | last post by:
I am trying to run a basic script that displays an existing jpeg image and writes some text over it. Sounds simple, but I cannot seem to be able to colour the font correctly. In the example below it should be black but it comes out orange. In fact, even if I change the colour to 0, 0, 255 it's orange. I've read in the PHP documentation (the user contributed notes) that there are issues with jpeg font colouring. But I've not seen any...
2
2688
by: Bjorn Sagbakken | last post by:
Hi. This story is about uploading jpg's, then resize them to fixed width or height and storing them to an SQL table. The only way I have found so far is to read the uploaded file to an image-variable, then using the method of creating thumbnails for the resizing. Next, I write this to a temp file on the disk, and read the file back to a byte array in order to insert/update the SQL table. Now, this works well, and even fast enough, no...
1
2150
by: jzieba | last post by:
Can someone tell me how to initialize the variable "display_image" below? The following code returns a bad source when it is first loaded. If I check properties on the image it states "Not Available" as the file name. The image is correctly displayed after the user makes a selection in the list box. Thanks for the help. <html><head><title>whatever</title> <script type="text/javascript"> var imageBlocks = new Array( 'new0.gif',
5
3892
by: Jeff | last post by:
hi asp.net 2.0 I get this compile error: 'Image' does not contain a definition for 'ImageUrl' Image image = (Image)e.Item.FindControl("img"); image.ImageUrl = "~/image.png";
6
20666
JOHNYKUTTY
by: JOHNYKUTTY | last post by:
i have to convert an image variable(system.drawing.bitmap orsystem.drawing.image or AForge.Imaging.Image) to Emgu.CV.Image type i have used the code below Image<Bgr, Byte> cvimage = new Image<Bgr, Byte>(bmp); but it is not working but also crashing the program When i put this code in a try block then it is not crashing. anyone can help me?????????????
0
9687
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
10482
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
10251
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
10225
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
10027
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
9072
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
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
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.