Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hiplease help me
how to change the images using javascript
i wrote the code but it not showing images
XML
<html>
<head>
    <title></title>
    <script language="javascript" type="text/javascript">
        var aryimgs = new Array("images/Chrysanthemum.jpg", "images/Desert.jpg", "images/Hydrangeas.jpg", "images/Jellyfish.jpg");
        var cnt = 0;
        function RotateImages() {
            setTimeout("ChangeImage()", 2000);
        }
        function ChangeImage() {
            cnt++;
            if (cnt == aryimgs.length)
                cnt = 0;
            document.getElementById("imgAd").src = aryimgs[cnt];
            RotateImages();
        }
    </script>
</head>
<body onload="RotateImages();">
    <center>
        <form id="form1" runat="server">
        <div>
            <input type="image" id="imgAd" style="width: 300px; height: 300px;" src="images/Chrysanthemum.jpg" />
        </div>
        </form>
    </center>
</body>
</html>
Posted
Comments
Sergey Alexandrovich Kryukov 11-Jul-12 12:23pm    
Change on what events or conditions? First, explain what did you want to achieve. Make sure the images are in the said directory, relative to this HTML file.
--SA

1 solution

It looked fine to me so I tried it out. It works perfectly fine for me. Images change by itself after every few seconds. No issues.

Recheck if images are present in the folder you are referring to.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900