• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Using Images

Let’s see some examples using images and JavaScript. The most basic type of image work is where you just swap images using the src property; here’s an example where the image displays when the page loads displays the text Image 1; but when you click a button, the code loads a new image, which displays Image 2:

(Listing 15-04.html on the web site)

<HTML> 
    <HEAD> 
        <TITLE> 
            Reloading Images 
        </TITLE> 

        <SCRIPT LANGUAGE="JavaScript"> 
            <!--
            function newImage()
					{
					document.form1.img1.src = "image2.jpg"
					} 
            //--> 
        </SCRIPT> 
    </HEAD> 

    <BODY> 
        <H1>Reloading Images</H1> 
        <FORM NAME="form1"> 
            <IMG NAME="img1" SRC="image1.jpg"
					WIDTH="216" HEIGHT="72"> 
            <BR> 
            <INPUT TYPE="BUTTON" Value="Load new image"
					ONCLICK="newImage()"> 
        </FORM> 
    </BODY> 
</HTML> 

					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint