[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

What is wrong with this function?

Posted on 2004-11-16
10
Medium Priority
?
364 Views
Last Modified: 2008-03-10
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..
0
Comment
Question by:adonis1976
  • 6
  • 4
10 Comments
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12598198
+(new Date()).getTime() instead of +Math.random()
0
 
LVL 11

Author Comment

by:adonis1976
ID: 12598231
did not work
0
 
LVL 11

Author Comment

by:adonis1976
ID: 12598236
it says object expected.. i dont think it is to do with Math function..
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Accepted Solution

by:
GwynforWeb earned 1000 total points
ID: 12598293
found it

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

Expert Comment

by:GwynforWeb
ID: 12598320
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
 
LVL 11

Author Comment

by:adonis1976
ID: 12598382
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
 
LVL 11

Author Comment

by:adonis1976
ID: 12598390
here is the page i'm talking about..

http://www.woodmen.com/falcons/falconcam/falconcam1.cfm
0
 
LVL 11

Author Comment

by:adonis1976
ID: 12598423
hey hold on.. i think i found the problem.. i will know in 2 mins.. i guess it is my stupid boss.
0
 
LVL 11

Author Comment

by:adonis1976
ID: 12598465
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
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12598496
thx, cool site we have falcons on a  building my way as well
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question