Here is a simple example (the error you got was because you missed the
brackets in the if statement).
<HEAD>
<script language ="javascript" >
var flag = true;
var img = null;
function init()
{
img = document.getElementById("TheImage");
timer = setInterval("TrackFrame()",500);
}
function TrackFrame()
{
if (flag == false)
{
img.src="pic1.jpg";
flag = true;
}
else
{
img.src="pic2.jpg";
flag = false;
}
}
</script>
</HEAD>
<BODY onload="init()">
<img src="pic1.jpg" id="TheImage">
</BODY>
"siaj" <> wrote in message
news:0469420E-B27E-4D92-A52B-...
> Thanks for quick reply...
> I tried the way u suggested though I had two doubts..
>
> My Javascript code goes as
> <script language ="javascript" >
> var flag = true;
> function init()
> {
> alert("I m here!");
> timer = setInterval("TrackFrame",500);
>
> }
> function TrackFrame()
> {
> if flag == false
> {
> alert("toggling");
> flag = true;
> }
> else
> {
> alert("toggled");
> flag = false;
> }
>
>
> }
> </script>
>
> I call from the body as
>
> <body MS_POSITIONING="GridLayout" onload = "init()">
>
> My doubts are that I get an error Expected "("
> also If you can tell me how to toggle the image in javascript.
>
> Let me confess that I am a beginner in web development.
>
> Appreciate your help..
> Cheers,
> siaj
>
> "Joseph Byrns" wrote:
>
>> You should do it in the JavaScript on the client so:
>>
>> function init()
>> {
>> timer = setInterval("TrackFrame()",500);
>> }
>>
>> function TrackFrame()
>> {
>> //toggle image here
>> }
>>
>> and call the init function from the body.
>>
>> "siaj" <> wrote in message
>> news:00591208-1D98-41B2-8088-...
>> > Hello,
>> > I am trying to put a very simple animation on a page. I want two
>> > images
>> > to
>> > show alternately in a defined area. I tried to have an image control
>> > and a
>> > timer control on a page. I am setting the Imageurl property of the
>> > image
>> > control to two difeent images at fixed time interval. but the image
>> > remains
>> > fixed on my page. It never resets to other image. Perhaps I need to
>> > Refresh
>> > the page at every timeinterval.
>> >
>> > My code is as
>> >
>> >
>> > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
>> > System.EventArgs) Handles MyBase.Load
>> > 'Put user code to initialize the page here
>> > SetTimer()
>> > End Sub
>> >
>> >
>> > Private Sub SetTimer()
>> > Try
>> > AddHandler Timer1.Elapsed, AddressOf OnTimer
>> > Timer1.Enabled = True
>> > Timer1.Interval = 1000
>> >
>> > Timer1.Start()
>> > Image1.ImageUrl = "C:\Sunset.jpg"
>> > Catch ex As Exception
>> > Response.Write(ex.Message)
>> > End Try
>> > End Sub
>> >
>> >
>> > Public Sub OnTimer(ByVal source As Object, ByVal e As ElapsedEventArgs)
>> > Try
>> > If Image1.ImageUrl = "C:\Sunset.jpg" Then
>> > Image1.ImageUrl = "C:\Winter.jpg"
>> > Else
>> > Image1.ImageUrl = "C:\Sunset.jpg"
>> > End If
>> >
>> >
>> > Catch ex As Exception
>> > Response.write(ex.Message)
>> > End Try
>> > End Sub
>> >
>> >
>> >
>> > Any suggestion shall be appreciated.
>> >
>> > Cheers,
>> > siaj
>>
>>
>>
|