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] 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)
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)
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)
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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. ...
|
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...
|
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....
|
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)...
|
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...
| |
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...
|
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...
|
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...
|
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....
|
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...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
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...
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |