473,507 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loading Image without refreshing

BN
Hello..:)

Is it possible to load and show a JPG file using Javascript...?

I have a HTML document, and want to load a new image when the user pushes a
button.

Thanx..

--
Best Regards,

BN - [E A Rosengrens AS]
Jul 20 '05 #1
4 5810
On Sat, 17 Jan 2004 16:37:14 GMT, BN <tn******@enter.vg> wrote:
Is it possible to load and show a JPG file using Javascript...?

I have a HTML document, and want to load a new image when the user
pushes a button.
Do you mean you want to change the source (src attribute) of an existing
IMG element when a user presses a button? If so, then yes, it can be done
as long as you accept the fact that a user with JavaScript disabled cannot
use this feature in your page.

Place this somewhere before the button below (HEAD or BODY):

<SCRIPT type="text/javascript">
function changeImage( element, URI ) {
var img = null;

if( document.getElementById ) {
img = document.getElementById( element );
} else if( document.all ) {
img = document.all[ element ];
}
if( img ) {
img.src = URI;
}
}
</SCRIPT>

In the BODY of your document:

<IMG id="giveMeAUniqueID" src="initialImage.jpg">
...
<BUTTON type="button"
onclick="changeImage('giveMeAUniqueID','newImage.j pg')"Change image</BUTTON>


replacing the two filenames and the ID name with your own values.

This will only allow the image to be changed once. Cycling between two or
more images, in sequential or random order, is equally possible, but as
you didn't ask for it, you're not getting it[1]. :P

Mike
[1] Obviously, ask if you do need such a feature.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
BN
Thanx, I will try this..

Is there also a way of handeling if the file does not excist...?

or to be exact:

My filenames consist of 2 or 4 characters. If a button loads the picture
2341.jpg and that image does not excist at the moment, I want 2300.jpg to be
loaded. And if 4356.jpg does not excist, I want to load 4300.jpg. ( The
first two bytes of the name + 00 )

--
Best Regards,

BN - [E A Rosengrens AS]
"Michael Winter" <M.******@blueyonder.co.invalid> skrev i melding
news:op**************@news-text.blueyonder.co.uk...
On Sat, 17 Jan 2004 16:37:14 GMT, BN <tn******@enter.vg> wrote:
Is it possible to load and show a JPG file using Javascript...?

I have a HTML document, and want to load a new image when the user
pushes a button.


Do you mean you want to change the source (src attribute) of an existing
IMG element when a user presses a button? If so, then yes, it can be done
as long as you accept the fact that a user with JavaScript disabled cannot
use this feature in your page.

Place this somewhere before the button below (HEAD or BODY):

<SCRIPT type="text/javascript">
function changeImage( element, URI ) {
var img = null;

if( document.getElementById ) {
img = document.getElementById( element );
} else if( document.all ) {
img = document.all[ element ];
}
if( img ) {
img.src = URI;
}
}
</SCRIPT>

In the BODY of your document:

<IMG id="giveMeAUniqueID" src="initialImage.jpg">
...
<BUTTON type="button"
onclick="changeImage('giveMeAUniqueID','newImage.j pg')"
>Change image</BUTTON>


replacing the two filenames and the ID name with your own values.

This will only allow the image to be changed once. Cycling between two or
more images, in sequential or random order, is equally possible, but as
you didn't ask for it, you're not getting it[1]. :P

Mike
[1] Obviously, ask if you do need such a feature.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)

Jul 20 '05 #3
On Sat, 17 Jan 2004 18:43:07 GMT, BN <tn******@enter.vg> wrote:
Is there also a way of handeling if the file does not excist...?


Not that I know of[1].

Mike
[1] That doesn't necessarily mean there isn't a way.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #4

You would have to use server side coding to do this .. like asp.


On Sat, 17 Jan 2004 18:43:07 GMT, "BN" <tn******@enter.vg> wrote:
Thanx, I will try this..

Is there also a way of handeling if the file does not excist...?

or to be exact:

My filenames consist of 2 or 4 characters. If a button loads the picture
2341.jpg and that image does not excist at the moment, I want 2300.jpg to be
loaded. And if 4356.jpg does not excist, I want to load 4300.jpg. ( The
first two bytes of the name + 00 )

--
Best Regards,

BN - [E A Rosengrens AS]
"Michael Winter" <M.******@blueyonder.co.invalid> skrev i melding
news:op**************@news-text.blueyonder.co.uk...
On Sat, 17 Jan 2004 16:37:14 GMT, BN <tn******@enter.vg> wrote:
> Is it possible to load and show a JPG file using Javascript...?
>
> I have a HTML document, and want to load a new image when the user
> pushes a button.


Do you mean you want to change the source (src attribute) of an existing
IMG element when a user presses a button? If so, then yes, it can be done
as long as you accept the fact that a user with JavaScript disabled cannot
use this feature in your page.

Place this somewhere before the button below (HEAD or BODY):

<SCRIPT type="text/javascript">
function changeImage( element, URI ) {
var img = null;

if( document.getElementById ) {
img = document.getElementById( element );
} else if( document.all ) {
img = document.all[ element ];
}
if( img ) {
img.src = URI;
}
}
</SCRIPT>

In the BODY of your document:

<IMG id="giveMeAUniqueID" src="initialImage.jpg">
...
<BUTTON type="button"
onclick="changeImage('giveMeAUniqueID','newImage.j pg')"
>Change image</BUTTON>


replacing the two filenames and the ID name with your own values.

This will only allow the image to be changed once. Cycling between two or
more images, in sequential or random order, is equally possible, but as
you didn't ask for it, you're not getting it[1]. :P

Mike
[1] Obviously, ask if you do need such a feature.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)



I participate in the group to help give examples of code. I do not guarantee the effects of any code posted. Test all code before use!

Brynn
www.coolpier.com
Jul 20 '05 #5

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

Similar topics

2
2530
by: jdi | last post by:
Hello, I have a seemingly basic question about ASP.NET. I would like to create a page containing an image, which keeps swapping the url of the image source, without refreshing the entire page. ...
0
1308
by: Jeronimo Bertran | last post by:
Hi, I have a page that includes an image that uses an image map. When the user clicks on a button, the image needs to be refreshed and the map needs to be updated without refreshing the entire...
6
2552
by: Ivan Bútora | last post by:
I have recently looked at http://alistapart.com/articles/imagegallery to implement a simple picture gallery on a webpage that I'm working on. Everything works fine; however, I have one question....
6
6427
by: Mark Denardo | last post by:
My question is similar to one someone posted a few months back, but I don't see any replies. Basically I want to be able to have users upload photos and save them in a database (as byte data)...
10
13361
by: eholz1 | last post by:
Hello Members, I am setting up a photo website. I have decided to use PHP and MySQL. I can load jpeg files into the table (medium blob, or even longtext) and get the image(s) to display without...
0
1694
by: AndySummers | last post by:
Hi We have just re-written a majour asp.net project to use a user control embedded in a web page. The main dll references 3 other custom controls and so to deploy the project I copy the 4 dll's to...
1
2365
by: pdesai007 | last post by:
hello, i tried to upload an image in to server with asp and java script ( using AJAX) but it gave an error. so please give me any solution that help me to upload an image to server with java...
3
1696
by: hegdepras | last post by:
Hi, I need to load only the image in a JSP without refreshing the entire page. I have an action class which sends the stream of the image and I call this action class from 'src' of <img> tag in...
6
2221
by: mistral | last post by:
Is there way change image (swap) on click on thumbnail without javascript? I.e. main image is big(preview), and below it is two small images - when click on small image, it should change big image....
0
7114
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...
0
7321
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,...
1
7034
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...
0
7488
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...
0
5623
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,...
1
5045
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...
0
3191
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...
0
1544
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 ...
1
762
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.