What is wrong with this function?

function onPageLoad()
 {
    if(document.getElementById('imgToLoad'))
      
      setInterval(
      "document.images['imgToLoad'].src='http://www.domain.com/falcons/falconcam/falcon_00001.jpg?rnd='+Math.random();",120000)
      else if(document.getElementById('Camera1'))
      setInterval(
 "document.images['Camera1'].src='http://www.domain.com/falcons/camera1.jpg?rnd='+Math.random();",120000)
      
else if(document.getElementById('Camera2'))
setInterval(
"document.images['Camera2'].src='http://www.domain.com/falcons/camera2.jpg?rnd='+Math.random();",120000)
else if(document.getElementById('Camera3'))
setInterval(
"document.images['Camera3'].src='http://www.domain.com/falcons/camera3.jpg?rnd='+Math.random();",120000)
else if(document.getElementById('Camera4'))
setInterval(
"document.images['Camera4'].src='http://www.domain.com/falcons/camera4.jpg?rnd='+Math.random();",120000)
)
}

and i have the images with the id 'imgToLoad','Camera1' and so on as you see in the code..  and i'm invoking the onPageLoad function in the body tag of the page.. pls help.. My objective is to refresh the image in the page..
LVL 11
adonis1976Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GwynforWebCommented:
+(new Date()).getTime() instead of +Math.random()
0
adonis1976Author Commented:
did not work
0
adonis1976Author Commented:
it says object expected.. i dont think it is to do with Math function..
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

GwynforWebCommented:
found it

setInterval(
"document.images['Camera4'].src='http://www.domain.com/falcons/camera4.jpg?rnd='+Math.random();",120000)
)  <-----extra bracket here
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GwynforWebCommented:
this works

<script>
 function onPageLoad()
 {
    if(document.getElementById('imgToLoad'))    
     setInterval(   "document.images['imgToLoad'].src='http://www.domain.com/falcons/falconcam/falcon_00001.jpg?rnd='+Math.random();",1500)
     else if(document.getElementById('Camera1'))
     setInterval(
 "document.images['Camera1'].src='http://www.domain.com/falcons/camera1.jpg?rnd='+Math.random();",120000)
     
else if(document.getElementById('Camera2'))
setInterval(
"document.images['Camera2'].src='http://www.domain.com/falcons/camera2.jpg?rnd='+Math.random();",120000)
else if(document.getElementById('Camera3'))
setInterval(
"document.images['Camera3'].src='http://www.domain.com/falcons/camera3.jpg?rnd='+Math.random();",120000)
else if(document.getElementById('Camera4'))
setInterval(
"document.images['Camera4'].src='http://www.domain.com/falcons/camera4.jpg?rnd='+Math.random();",120000)

}

</script>

<body onload="onPageLoad()">
<img id="imgToLoad" src="http://www.google.ca/intl/en_ca/images/logo.gif" width="276"
height="110" alt="logo[2].gif (8914 bytes)"></p>
</body>
0
adonis1976Author Commented:
yeah u were right.. by getting rid of that ')', i got rid of the javascript erros.. thanks for that..

now i seem to have a different problem.. if I'm on the page that has id Camera1, it loads the image 'imgToLoad' after 2 mins.. I thought I took care of that by having an if statement.. pls correct me if i'm wrong..
0
adonis1976Author Commented:
here is the page i'm talking about..

http://www.woodmen.com/falcons/falconcam/falconcam1.cfm
0
adonis1976Author Commented:
hey hold on.. i think i found the problem.. i will know in 2 mins.. i guess it is my stupid boss.
0
adonis1976Author Commented:
hey thanks for all your help.. u are awesome.. the error was from the html code, cos he had id-ed the image wrongly.. not a problem in the script..
0
GwynforWebCommented:
thx, cool site we have falcons on a  building my way as well
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.