Webmaster Cash Program
 Upload & Sell Your Software
Upload & Sell Your Ebook
 Enter The AWT Service Center  Contact Applied Web Tools
 Purchase Some Advertising  Password Troubles? Click Here!
Knowledge Center
Want to write for Applied Web Tools? Send your Writer's Query to
Editor@AppliedWebTools.net for details.
HTML
Reference
&
Tutorial
CSS
Reference
&
Tutorial
DOM
Reference
&
Tutorial
JavaScript
Reference
&
Tutorial
50+ Programming Examples
Use HTML, CSS, DOM & JavaScript Together
Misc. Essays & Documents
You'll Find Just About Anything In Here
50+ Web Page Constructions
Learn the Art of Using HTML, CSS, DOM & JavaScript Together
 Changing Background Colors
 Event Triggering With onLoad
 Disabling The Right Click
 DOM Driven Color Changing
 Switching Images
 innerHTML Attribute Access
 Change With innerHTML
 Changing Positions
 Change Position With onMouseMove
 Change Text Position
 Interactivity Skills
 Type-writing A Message
 Auto-changing Text Size
 Making Text Scroll
 Blinking Text
 Simple Form Authentication
 Change Background Color Of An INPUT
 Change Text Color Of An INPUT
 Change Background Image Of An INPUT
 Select All Checkboxes
 Select Color Of The Submit Button
 Change Text Color Of A Submit Button
 Insert Background Image To A Button
 Change Color Of Drop Down List
 Change Text Color Of A Drop Down List
 Change Color Of A TEXTAREA
 Change The Text Color Of A TEXTAREA
 Insert An Image Into A TEXTAREA
 Change The Size Of An Image
 Change The Source Of An Image
 Change The Position Of An Image
 Change The Background Image
 Moving Images Around The Page
 Drag & Drop An Image
 A Simple Image Viewer
 A Shaking Image
 A Digital Clock
 Drop Down List Link
 Top Drop Down Menu
 Always On Top Menu
 Inset Border Buttons
 A Description Generating Menu
 An Image Generating Menu
 A Horizontal Sliding Menu
 A Click Horizontal Sliding Menu
 Returning Cursor Co-ordinates
 Making Text Follow The Cursor
 Attaching An Image To The Cursor
switching images

Switching images is fairly simple as long as you realize a couple of things: you must preload the image data that you want to switch to into a variable, and if you want to change the image back you have to load the original image data into a variable of its own. You accomplish through the use of the src attribute of the document object. Examine the below example:

<html>
<body>

<img id="image" src="smiley.gif" width="160" height="120">

<script type="text/javascript">
document.getElementById("image").src="landscape.jpg";
</script>

<p>The original image was smiley.gif, but the script changed it to landscape.jpg</p>

</body>
</html>


You can place the JavaScript function that accomplishes this action in any place within the document. However, older browsers require that you place the function in a section of the document that is parsed before the location of the image is stated to be changed. You can use a JavaScript function within the opening and closing SCRIPT tags or you can use a javascript: parameter of any given legal tag within the HTML 4.0 specifications.

To change the image back to the original image, you must use the same src attribute of the document object to do so – simply change the URL of the image file. The browser will load the data and store it until it is triggered with the event handler of your choice.

In the example above we used two variables to store and retrieve the image data. It is entirely possible, and in some cases, desirable, to use one array rather than many variables. Simple declare the array, assign the src attribute in the exact way given above, but use an arrayName[count]= assignment instead of a simple variable declaration.

You would use this technique if you need to change many different images in many different portions of the document, at different times. You should use variables if you wish to change many images that are the same at the same time – the image data stored in the variable will be used repeatedly.
Want a copy of the Applied Web Tools Knowledge Center on your site?

Over 1200 individual command definitions in a really cool interface

Send your query to Sales@AppliedWebTools.net for details
I do not employ cookies or tracking devices of any kind