Purchase Advertising On AWT
 Upload & Sell Your Software
 Upload & Sell Your eBook
 Enter The AWT Control Panel  Contact Applied Web Tools
 Sell Your eBook @ The PDF Store  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
change background image of an input field

There are many web sites that use this small but powerful chunk of functionality. The Internet is based on look and feel, so it is obviously very common to have to work with a large amount of display options. The easiest to understand is simply changing the background image used in a text input field.

We use a pre-loader to fetch the image data that is going to be displayed. The src attribute of the document object is used to tell the browser the location of the file. Upon the page loading, the data for the image is fetched and stored and is immediately available to the entire page. It should be noted that if you wish to switch the displayed image back to the original image, you would have to use another src attribute statement to fetch the original image data and store it. You may then provide to have the image switched back according to your requirements.

<html>
<head>

<script type="text/javascript">
function bgChange(bg) {
document.getElementById('x').style.background="url(" + bg + ")";
}
</script>

</head>

<body>

<p>This example demonstrates how to insert a background image to an input field</p>
<p>Mouse over these images and the input field will get a background image.</p>

<table width="300" height="100">
<tr>
<td onmouseover="bgChange('paper.jpg')" background="paper.jpg"></td>
<td onmouseover="bgChange('bgdesert.jpg')" background="bgdesert.jpg"></td>
</tr>
</table>

<form>
<input id="x" type="text" value="Mouse over the images" size="20">
</form>

</body>
</html>


Use a simple id attribute to uniquely identify the page element to apply the change to. This id is used as the argument of the getElementById object. We then use a style.background attribute to select from the many style sheet options available and apply the new value when the onMouseOver event is triggered. You may use a relative or absolute URL for the location of the image file and the image format can be any that the browser supports, in this case a .jpg.
I do not employ cookies or tracking devices of any kind